1、将数字转为ip地址:IPAdd_DotNumFormat
create or replace FUNCTION IPAdd_DotNumFormat(v_LfValue number)return varchar2 asv_DotNumString varchar2(50);v_flg Integer;v_NewLfValue number;v_tmp Integer;v_P1 Integer;v_P2 Integer;v_P3 Integer;v_P4 Integer;
beginv_flg := 1;if (v_LfValue < 0) thenv_flg := -1;end if;v_NewLfValue := sign(v_LfValue) * v_LfValue;v_tmp := floor(v_NewLfValue);v_P1 := mod(v_tmp,256);v_P2 := mod(((v_tmp - v_P1) / 256),256);v_P3 := mod((((v_tmp - v_P1) /256 - v_P2) / 256),256);v_P4 := mod(((((v_tmp - v_P1) /256 - v_P2) / 256 - v_P3) / 256 ),256);if (v_flg < 0) thenv_P1 := 256 - v_P1;v_P2 := 255 - v_P2;v_P3 := 255 - v_P3;v_P4 := 255 - v_P4;end if;v_DotNumString := to_char(v_P4) || '.' || to_char(v_P3) || '.' || to_char(v_P2) || '.' || to_char(v_P1);return v_DotNumString;
end;
测试:
select ipadd_dotnumformat(2026637868),table_name from user_tables;
效果: