MYSQL Equivalent INET_NTOA and INET_ATON for Oracle

create or replace function inet_aton( p_str in varchar2 ) return
number
as
l_dot1 number := instr( p_str, ‘.’,1,1 );
l_dot2 number := instr( p_str, ‘.’,1,2 );
l_dot3 number := instr( p_str, ‘.’,1,3 );
begin
return
to_number(substr(p_str,1,l_dot1-1))*power(256,3)+
to_number(substr(p_str,l_dot1+1, l_dot2-l_dot1-1))*power(256,2)+
to_number(substr(p_str,l_dot2+1,l_dot3-l_dot2-1))*256+
to_number(substr(p_str,l_dot3+1));
end;
/

create or replace function inet_ntoa( ip_addr in integer ) return
string
as
begin
return
mod( trunc(ip_addr/256/256/256), 256 ) || ‘.’ ||
mod( trunc(ip_addr/256/256), 256 ) || ‘.’ ||
mod( trunc(ip_addr/256), 256 ) || ‘.’ ||
mod( ip_addr , 256 );
end;
/

select ip_addr, inet_aton( ip_addr ),inet_ntoa( inet_aton( ip_addr ))
from
(
select ’209.207.224.90′ ip_addr from dual
)
/

original source: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:2102503700346287503

Popularity: 19% [?]

0 Responses to “MYSQL Equivalent INET_NTOA and INET_ATON for Oracle”


  1. No Comments

Leave a Reply

CommentLuv Enabled



Subscribe

Subscribe to my RSS Feeds