oracle切割以,隔开的数字字符串

提前声明strsplit_type
CREATE OR REPLACE TYPE strsplit_type as table of varchar2(4000);

如果不,会报错:
PLS-00201: 必须声明标识符 'strsplit_type'


--strsplit 数据:2,4,5,6,7,8,9

1
create or replace function strsplit(p_value varchar2, 2 p_split varchar2 := ',') 3 4 return strsplit_type 5 pipelined is 6 v_idx integer; 7 v_str varchar2(500); 8 v_strs_last varchar2(4000) := p_value; 9 10 begin 11 loop 12 v_idx := instr(v_strs_last, p_split); 13 exit when v_idx = 0; 14 v_str := substr(v_strs_last, 1, v_idx - 1); 15 v_strs_last := substr(v_strs_last, v_idx + 1); 16 pipe row(v_str); 17 end loop; 18 pipe row(v_strs_last); 19 return; 20 21 end strsplit;
 1 create or replace function split(p_value varchar2,p_sep varchar2 := ',')
 2 --usage: select * from table(strsplit('1,2,3,4,5'))
 3  return type_split
 4   pipelined is
 5   v_idx       integer;
 6   v_str       varchar2(500);
 7   v_strs_last varchar2(4000) := p_value;
 8 
 9 begin
10   loop
11     v_idx := instr(v_strs_last, p_value);
12     exit when v_idx = 0;
13     v_str       := substr(v_strs_last, 1, v_idx - 1);
14     v_strs_last := substr(v_strs_last, v_idx + 1);
15     pipe row(v_str);
16   end loop;
17   pipe row(v_strs_last);
18   return;
19 
20 end split;
原文地址:https://www.cnblogs.com/kingxiaozi/p/4648161.html