create or replace type tb_strSplit as table of varchar2(4000);
create or replace function to_table(pv_str varchar2,pv_split varchar2) return tb_strSplit
as
ltab tb_strSplit := tb_strSplit();
pos integer := 0;
ls varchar2(4000) := pv_str;
begin
pos := instr(ls,pv_split);
while pos > 0 loop
ltab.extend;
ltab(ltab.count) := substr(ls,1,pos - 1);
ls := substr(ls,pos + length(pv_split));
pos := instr(ls,pv_split);
end loop;
ltab.extend;
ltab(ltab.count) := ls;
return ltab;
end;
set serverout on
declare
aa tbl_str;
begin
aa := to_table('a|||b|||c','|||');
for i in 1..aa.count loop
dbms_output.put_line(aa(i));
end loop;
end;
/
----------------------------------------------------------
CREATE OR REPLACE function strToTb(inVStr in string,inStrSplit in varchar) return tb_strSplit PIPELINED
as
v_tmp varchar2(4000);
v_element varchar2(4000);
begin
v_tmp := inVStr;
while instr(v_tmp,inStrSplit)>0 loop
v_element := substr(v_tmp,1,instr(v_tmp,inStrSplit)-1);
v_tmp := substr(v_tmp,instr(v_tmp,inStrSplit)+length(inStrSplit),length(v_tmp));
pipe row(v_element);
end loop;
pipe row(v_tmp);
return;
end strToTb;
/
select * from table(strToTb('a|||b|||c','|||'));