1. 程式人生 > >oracle ip地址轉換為整數 整數轉換為ip程式碼

oracle ip地址轉換為整數 整數轉換為ip程式碼

2:ip地址轉換為整數:

在oracle中建立如下函式即可:

create or replace function striptoint( dottedQuad IN VARCHAR2) return number is

  Result NUMBER;

begin

  Result:= (substr(dottedQuad ,

            1,

            (instr(dottedQuad , '.', 1, 1 ) - 1))

            * 256 * 256 * 256

    ) +

    (substr(dottedQuad ,

            instr(dottedQuad , '.', 1, 1 ) + 1,

            instr(dottedQuad , '.', 1, 2 ) -

            instr(dottedQuad , '.', 1, 1 ) - 1) * 256 * 256

    ) +

    (substr(dottedQuad ,

            instr(dottedQuad , '.', 1, 2 ) + 1,

            instr(dottedQuad , '.', 1, 3 ) -

            instr(dottedQuad , '.', 1, 2 ) - 1) * 256

    ) +

    (substr(dottedQuad ,

            instr(dottedQuad , '.', 1, 3 ) + 1)

    ) ;

  return(Result );

end iptoint ;

使用:

select  striptoint('10.10.10.10')  from  dual

結果:

168430090