|
- /*自定义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',','));
复制代码
|
|