<tfoot id='aqvNX'></tfoot>

      <legend id='aqvNX'><style id='aqvNX'><dir id='aqvNX'><q id='aqvNX'></q></dir></style></legend>
        • <bdo id='aqvNX'></bdo><ul id='aqvNX'></ul>
        <i id='aqvNX'><tr id='aqvNX'><dt id='aqvNX'><q id='aqvNX'><span id='aqvNX'><b id='aqvNX'><form id='aqvNX'><ins id='aqvNX'></ins><ul id='aqvNX'></ul><sub id='aqvNX'></sub></form><legend id='aqvNX'></legend><bdo id='aqvNX'><pre id='aqvNX'><center id='aqvNX'></center></pre></bdo></b><th id='aqvNX'></th></span></q></dt></tr></i><div id='aqvNX'><tfoot id='aqvNX'></tfoot><dl id='aqvNX'><fieldset id='aqvNX'></fieldset></dl></div>
      1. <small id='aqvNX'></small><noframes id='aqvNX'>

      2. IP 地址存储为十进制 - PL/SQL 显示为点四边形

        IP address stored as decimal - PL/SQL to display as dotted quad(IP 地址存储为十进制 - PL/SQL 显示为点四边形)

            <legend id='R3NIZ'><style id='R3NIZ'><dir id='R3NIZ'><q id='R3NIZ'></q></dir></style></legend>
          • <tfoot id='R3NIZ'></tfoot>

              <small id='R3NIZ'></small><noframes id='R3NIZ'>

                <tbody id='R3NIZ'></tbody>
                <bdo id='R3NIZ'></bdo><ul id='R3NIZ'></ul>

                  <i id='R3NIZ'><tr id='R3NIZ'><dt id='R3NIZ'><q id='R3NIZ'><span id='R3NIZ'><b id='R3NIZ'><form id='R3NIZ'><ins id='R3NIZ'></ins><ul id='R3NIZ'></ul><sub id='R3NIZ'></sub></form><legend id='R3NIZ'></legend><bdo id='R3NIZ'><pre id='R3NIZ'><center id='R3NIZ'></center></pre></bdo></b><th id='R3NIZ'></th></span></q></dt></tr></i><div id='R3NIZ'><tfoot id='R3NIZ'></tfoot><dl id='R3NIZ'><fieldset id='R3NIZ'></fieldset></dl></div>

                  本文介绍了IP 地址存储为十进制 - PL/SQL 显示为点四边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们有一个 Oracle 数据库,其中包含存储为十进制整数的 IP 地址 - 当手动操作数据而不是通过 Web 界面时,这非常痛苦,但手动操作非常方便,因为网络人员不断要求我们做奇怪的事情Web 界面作者没有预料到的事情.

                  We have an Oracle database that contains IP addresses stored as decimal integers - this is incredibly painful when manipulating the data by hand instead of via the web interface, yet hand manipulation is really handy as the network guys continually ask us to do strange things that the web interface authors did not anticipate.

                  有人能给我提供 PL/SQL 或其他方法来将这些十进制 IP 显示为点分十进制,即 123.123.123.123 格式吗?

                  Could someone provide me with the PL/SQL or other method to display these decimal IPs as dotted decimal i.e. 123.123.123.123 format?

                  即我希望能够运行查询,例如:

                  I.e. I'd like to be able to run a query such as :

                  select hostname, inttoip(ip_address) from host;
                  

                  并让 inttoip() 过程将 ip_address 显示为 203.30.237.2 而不是 3407801602.

                  and have the inttoip() procedure display ip_address as 203.30.237.2 instead of as 3407801602.

                  理想情况下,我想要一个也提供反函数的过程,例如

                  Ideally I'd like a procedure which provides the inverse function too, e.g.

                  insert into host (hostname,ip_address) values ('some-hostname', iptoint('203.30.237.2'));
                  

                  我有 perl 来做这件事,但我的 PL/SQL/Oracle 知识不足以将它移植到 PL/SQL.

                  I have perl to do this, but my PL/SQL/Oracle knowledge is not good enough to port it into PL/SQL.


                  或者一种在 oracle 上下文中将 perl 作为过程语言运行的方法,类似于 postgres 中的以下内容:

                  Alternatively a way to run the perl as the procedural language within the oracle context analogous to the following in postgres:

                  CREATE FUNCTION perl_func (integer) RETURNS integer AS $$
                   <some perl>
                  $$ LANGUAGE plperl;
                  

                  会很棒 - 如果可能的话 - 可能会更好,因为我可以用我熟悉的语言在 Oracle 中做很多程序性的事情.

                  Would be great - if possible - probably even better as I could then do lots of procedural stuff within Oracle in a language I am familiar with.

                  推荐答案

                  这是你需要的功能:

                  create or replace
                  function inttoip(ip_address integer) return varchar2
                  deterministic
                  is
                  begin
                      return to_char(mod(trunc(ip_address/256/256/256),256))
                             ||'.'||to_char(mod(trunc(ip_address/256/256),256))
                             ||'.'||to_char(mod(trunc(ip_address/256),256))
                             ||'.'||to_char(mod(ip_address,256));
                  end;
                  

                  (关于使函数具有确定性和使用 to_char 的评论 - 谢谢).

                  (Comments about making function deterministic and using to_char taken on board - thanks).

                  在 Oracle 11G 中,您可以将格式化的 IP 地址设置为主机表上的虚拟列:

                  In Oracle 11G you could make the formatted IP address a virtual column on the host table:

                  alter table host
                  add formatted_ip_address varchar2(15)
                  generated always as
                  ( to_char(mod(trunc(ip_address/256/256/256),256))
                            ||'.'||to_char(mod(trunc(ip_address/256/256),256))
                            ||'.'||to_char(mod(trunc(ip_address/256),256))
                            ||'.'||to_char(mod(ip_address,256))
                  ) virtual;
                  

                  如果需要,可以为该列编制索引以进行查询.

                  This column could then be indexed for queries if required.

                  您的查询变为:

                  select hostname, formatted_ip_address from host;
                  

                  这篇关于IP 地址存储为十进制 - PL/SQL 显示为点四边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to call Oracle function or stored procedure using spring persistence framework?(如何使用 Spring 持久化框架调用 Oracle 函数或存储过程?)
                  What can cause intermittent ORA-12519 (TNS: no appropriate handler found) errors(什么会导致间歇性 ORA-12519(TNS:找不到合适的处理程序)错误)
                  SQL to return the number of working days between 2 passed in dates(SQL 返回两个传入日期之间的工作日数)
                  Oracle Date Subtraction(Oracle 日期减法)
                  Is using quot;select *quot; for a cursor in PL/SQL considered bad programming?(正在使用“选择 *PL/SQL 中的游标被认为是糟糕的编程?)
                  Using sql/plsql, how do you find out which character set a text uses?(使用 sql/plsql,你如何找出文本使用的字符集?)

                    <small id='sYT8I'></small><noframes id='sYT8I'>

                      <i id='sYT8I'><tr id='sYT8I'><dt id='sYT8I'><q id='sYT8I'><span id='sYT8I'><b id='sYT8I'><form id='sYT8I'><ins id='sYT8I'></ins><ul id='sYT8I'></ul><sub id='sYT8I'></sub></form><legend id='sYT8I'></legend><bdo id='sYT8I'><pre id='sYT8I'><center id='sYT8I'></center></pre></bdo></b><th id='sYT8I'></th></span></q></dt></tr></i><div id='sYT8I'><tfoot id='sYT8I'></tfoot><dl id='sYT8I'><fieldset id='sYT8I'></fieldset></dl></div>
                      <tfoot id='sYT8I'></tfoot>
                      <legend id='sYT8I'><style id='sYT8I'><dir id='sYT8I'><q id='sYT8I'></q></dir></style></legend>

                          <bdo id='sYT8I'></bdo><ul id='sYT8I'></ul>
                            <tbody id='sYT8I'></tbody>