0

将原始数字转换为 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;
4

0 回答 0