方法一
拆分效果
创建自定义数组类型
create or replace type strArray as table of varchar2(4020)
创建拆分函数
--此方法只能使用英文半角逗号(,)
create or replace function f_split(instr IN VARCHAR2) return strArray
as
l_tablen BINARY_INTEGER;
l_tab DBMS_UTILITY.uncl_array;
l_ret strArray:=strArray();
BEGIN
DBMS_UTILITY.comma_to_table(instr, l_tablen, l_tab);
FOR i IN 1 .. l_tablen LOOP
l_ret.EXTEND(1);
l_ret(i):=l_tab(i);
END LOOP;
return l_ret;
END;
函数调用
select t.column_value as value from table(f_split('a,b,付')) t;
方法二
拆分效果
创建自定义数组类型
create or replace type strArray as table of varchar2(4020)
创建拆分函数
CREATE OR REPLACE FUNCTION f_split(p_str IN VARCHAR2, p_delimiter IN VARCHAR2)
RETURN strArray IS
TYPE ret_cur IS REF CURSOR;
ret_cur1 ret_cur;
g_str strarray:=strarray();
l_sql varchar2(500):='';
BEGIN
l_sql :='SELECT REGEXP_SUBSTR ('''||p_str||''',''[^'||p_delimiter||']+'',1,LEVEL) as valuesa
FROM DUAL
CONNECT BY REGEXP_SUBSTR ('''||p_str||''',''[^'||p_delimiter||']+'',1,LEVEL) IS NOT NULL';
OPEN ret_cur1 FOR l_sql ;
FETCH ret_cur1 BULK COLLECT INTO g_str;
CLOSE ret_cur1;
RETURN g_str;
END f_split;
函数调用
select * from table(f_split('abc$d$e$','$') );