/自定義oracle的分割函數/
/定義一個type,用戶接收返回的數據集合類型/
create or replace type splitType as table of varchar2(4000);
/*
參數1: 被分割的字符串
參數2:分割字符串,默認是英文逗號
*/
create or replace function split_str(str varchar2, split_char varchar2:=',')
return splitType pipelined
is
idx number(4);
orgin_str varchar2(1000):=str;
temp_str varchar2(1000);
begin
idx:=instr(orgin_str,split_char);
loop
exit when idx=0;
temp_str:=substr(orgin_str,1,idx-1);
pipe row(temp_str);
orgin_str:=substr(orgin_str,idx+1);
idx:=instr(orgin_str,split_char);
end loop;
pipe row(orgin_str);
return;
end;
/測試/
select * from table(split_str('king,arise',','));
end;