转自:http://blog.youkuaiyun.com/xys_777/article/details/6959451
资料一:
PL/SQL 中没有split函数,需要自己写。
代码:
create or replace type type_split as table of varchar2(50); --创建一个 type ,如果为了使split函数具有通用性,请将其size 设大些。


--创建function
create or replace function split
(
p_list varchar2,
p_sep varchar2 := ','
) return type_split pipelined
is
l_idx pls_integer;
v_list varchar2(50) := p_list;
begin
loop
l_idx := instr(v_list,p_sep);
if l_idx > 0 then
pipe row(substr(v_list,1,l_idx-1));
v_list := substr(v_list,l_idx+length(p_sep));
else
pipe row(v_list);
exit;
end if;
end loop;
return;
end split;
测试:

SQL> select * from table(split('northsnow,塞北的雪',','));

COLUMN_VALUE
--------------------------------------------------
northsnow
塞北的雪

SQL>
本文介绍了如何在PL/SQL中实现字符串分割功能,通过创建自定义函数split,该函数可以将输入字符串按照指定分隔符分割成多个部分,并逐行输出结果。演示了函数的应用实例,包括使用示例代码和SQL查询来验证函数正确性。
1101

被折叠的 条评论
为什么被折叠?



