您的位置:首页 > 其它

看到返回TABLE的函数,还有不错的分解字串。

2010-01-26 17:26 211 查看
oracle的split函数

oracle 2008-07-22 14:18 阅读1488 评论0
字号:

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


塞北的雪
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐