从原始数字转换为IPV4或IPV6

时间:2012-11-02 16:54:22

标签: oracle plsql

将从原始数字转换为IPV4或IPV6的Oracle函数的任何来源?

CREATE or replace FUNCTION inttoip(ip_address IN INTEGER) RETURN VARCHAR2 IS
v8 varchar2(8);
ip_str varchar2(16) default null;
BEGIN
if ip_address is not null then
-- 1. convert the integer into hexadecimal representation
v8 := LPAD(TO_CHAR(ip_address, 'FMXXXXXXXX'),8,'0');
-- 2. convert each XX portion back into decimal
ip_str := to_number(substr(v8,1,2),'XX')
|| '.' || to_number(substr(v8,3,2),'XX')
|| '.' || to_number(substr(v8,5,2),'XX')
|| '.' || to_number(substr(v8,7,2),'XX');
end if;
return ip_str;
END inttoip;

0 个答案:

没有答案