1.创建type:
SQL> create or replace type test_type_split as table of varchar2(50);
2 /
Type created.
2.创建function:
SQL> create or replace function test_split
2 (
3 test_p_list varchar2, --要分割的字符串
4 test_p_sep varchar2 := ',' --分隔符,这里可以不用赋值,直接调用的时候给参数就行
5 ) return test_type_split pipelined --返回的管道是一个集合
6 is
7 test_list varchar2(50) := test_p_list; --把test_p_list的值赋给test_list,下面对test_list进行操作
8 begin
9 pipe row(substr(test_p_list, 0 , instr(test_p_list, test_p_sep)-1));
10 loop
11 test_list := substr(test_list, instr(test_list, test_p_sep)+1,length(test_list)-instr(test_list, test_p_sep)+1);
12 exit when instr(test_list,test_p_sep)=0;
13 pipe row(substr(test_list, 0, instr(test_list, test_p_sep)-1));
14 end loop;
15 pipe row(test_list);
16 return;
17 end test_split;
18 /
Function created.
3.测试: