oracle自定义函数按照某个分隔符拆分字符串
1.首先需要定义一个集合类型,我这里定义的是变长数组类型(VARRAY) create type type_splitstr is varray(1024) of varchar2(128); --注意,我这里之所以不用嵌套表类型(NESTED TABLE),是因为oracle官方文档有如下说明。 --Nested Tables: The indexes and row order of a nested table might not remain stable as you store and retrieve the nested table from the database. --Varrays (Variable-Size Arrays): When you store and retrieve a varray from the database,its indexes and element order remain stable. 2.创建自定义函数,实现字符串的拆分 create or replace function func_splitstr while instr(var_tmp,var_split) > 0 --如果存在匹配的分割符 var_out.extend; return var_out; / 使用: SQL> select * from table(func_splitstr('1|2|3,4|5|6',',')); COLUMN_VALUE SQL> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |