Pl/SQL 中的 SPLIT 函数
据我了解,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>
原文链接:http://blog.youkuaiyun.com/precipitant/archive/2007/08/15/1744943.aspx。
本文介绍了一种在PL/SQL中实现字符串拆分的方法,通过创建一个自定义的SPLIT函数来处理以特定字符分隔的字符串,并返回一个字符串列表。此方法适用于需要将字符串按指定分隔符进行拆分的场景。
1071

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



