Oacle 中实现split功能。
下面语句SQL/PLUS 执行即可。
应用如:SELECT COLUMN_VALUE FROM TABLE (dlsplit(list,','));
-------------------------------------------------------------------
create or replace type split_tbl as table of varchar2(32767);
/
create or replace function dlsplit(p_list varchar2, p_del varchar2 := ',') return split_tbl pipelined is
l_idx pls_integer;
l_list varchar2(32767) := p_list;
begin
loop
l_idx := instr(l_list, p_del);
if l_idx > 0 then
pipe row(substr(l_list, 1, l_idx - 1));
l_list := substr(l_list, l_idx + length(p_del));
else
pipe row(l_list);
exit;
end if;
end loop;
return;
end dlsplit;
/
下面语句SQL/PLUS 执行即可。
应用如:SELECT COLUMN_VALUE FROM TABLE (dlsplit(list,','));
-------------------------------------------------------------------
create or replace type split_tbl as table of varchar2(32767);
/
create or replace function dlsplit(p_list varchar2, p_del varchar2 := ',') return split_tbl pipelined is
l_idx pls_integer;
l_list varchar2(32767) := p_list;
begin
loop
l_idx := instr(l_list, p_del);
if l_idx > 0 then
pipe row(substr(l_list, 1, l_idx - 1));
l_list := substr(l_list, l_idx + length(p_del));
else
pipe row(l_list);
exit;
end if;
end loop;
return;
end dlsplit;
/