Oracle的几个Function实例
create or replace function str_list2( key_name in varchar2,
key in varchar2,
coname in varchar2,
tname in varchar2 )
return varchar2
as
type rc is ref cursor;
str varchar2(4000);
sep varchar2(2);
val varchar2(4000);
cur rc;
begin
open cur for 'select '||coname||'
from '|| tname || '
where ' || key_name || ' =
'
using key;
loop
fetch cur into val;
exit when cur%notfound;
str := str || sep || val;
sep := ', ';
end loop;
close cur;
return str;
end;
--------------------------------------------------------------
create or replace function ip_int2string(intip number) return varchar2 is
/**
* added by ty
* IP段整型格式转换为字符串格式
*
* 计算结果必须与com.zznode.inms.ipms.util.AlgorithmToolKit中的
* public static String getStringIp(int intIp)方法的计算结果一致
*/
Result varchar2(15);
min_int number;
temp number;
temp1 number;
temp2 number;
temp3 number;
temp4 number;
flag number;
begin
min_int:=-2147483648;
if intip<min_int or intip>2147483647 then
raise_application_error(-20020,'[IPMS] Illegal int IP!');
end if;
if intip<0 then
temp:=intip-min_int;
flag:=0;
else
temp:=intip;
flag:=1;
end if;
temp1:= bitand(floor(temp/(2**24)),255);--右移24位,进行与运算
temp2:= bitand(floor(temp/(2**16)),255);--右移16位,进行与运算
temp3:= bitand(floor(temp/(2**8)),255);--右移8位,进行与运算
temp4:= bitand(temp,255);--进行与运算
if flag=1 then
temp1:=temp1+128;
end if;
Result:=temp1||'.'||temp2||'.'||temp3||'.'||temp4;
dbms_output.put_line(Result);
return(Result);
exception
when others then
raise_application_error(-20020,'[IPMS] Illegal int IP!');
end ip_int2string;
--------------------------------------------------------------
create or replace function ip_string2int(stringip varchar2) return number is
/**
* added