ops$tkyte%ORA11GR2> select ip_addr,
2 to_number(substr(ip_addr,1,instr(ip_addr,'.')-1))*power(256,3)+
3 to_number(substr(ip_addr,instr(ip_addr,'.')+1,instr(ip_addr,'.',1,2)-instr(ip_addr,'.')-1))*power(256,2)+
4 to_number(substr(ip_addr,instr(ip_addr,'.',1,2)+1,instr(ip_addr,'.',1,3)-instr(ip_addr,'.',1,2)-1))*256+
5 to_number(substr(ip_addr,instr(ip_addr,'.',1,3)+1)) inet_aton
6 from
7 (
8 select '209.207.224.40' ip_addr from dual
9 )
10 /
IP_ADDR INET_ATON
-------------- ----------
209.207.224.40 3520061480
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> create or replace function inet_aton( p_str in varchar2 ) return number
2 as
3 l_dot1 number := instr( p_str, '.',1,1 );
4 l_dot2 number := instr( p_str, '.',1,2 );
5 l_dot3 number := instr( p_str, '.',1,3 );
6 begin
7 return
8 to_number(substr(p_str,1,l_dot1-1))*power(256,3)+
9 to_number(substr(p_str,l_dot1+1, l_dot2-l_dot1-1))*power(256,2)+
10 to_number(substr(p_str,l_dot2+1,l_dot3-l_dot2-1))*256+
11 to_number(substr(p_str,l_dot3+1));
12 end;
13 /
Function created.
ops$tkyte%ORA11GR2>
ops$tkyte%ORA11GR2> select ip_addr, inet_aton( ip_addr )
2 from
3 (
4 select '209.207.224.40' ip_addr from dual
5 )
6 /
IP_ADDR INET_ATON(IP_ADDR)
-------------- ------------------
209.207.224.40 3520061480
and simply because I'm a pessimist...
ops$tkyte%ORA11GR2> select ip_addr, inet_aton( ip_addr ),
2 mod( trunc(inet_aton( ip_addr )/256/256/256), 256 ) || '.' ||
3 mod( trunc(inet_aton( ip_addr )/256/256), 256 ) || '.' ||
4 mod( trunc(inet_aton( ip_addr )/256), 256 ) || '.' ||
5 mod( inet_aton( ip_addr ), 256 )
6 from
7 (
8 select '209.207.224.40' ip_addr from dual
9 )
10 /
IP_ADDR INET_ATON(IP_ADDR)
-------------- ------------------
MOD(TRUNC(INET_ATON(IP_ADDR)/256/256/256),256)||'.'||MOD(TRUNC(INET_ATON(IP_ADDR)/256/256),256)||'.'||MOD(TRUNC(INET_ATON
-------------------------------------------------------------------------------------------------------------------------
209.207.224.40 3520061480
209.207.224.40
I have a feeling the reverse question might be lurking next.