首页 > 代码库 > oracle 数据库 分割字符串返回结果集函数
oracle 数据库 分割字符串返回结果集函数
CREATE OR REPLACE FUNCTION "UFN_SPLIT" ( p_list varchar2, p_sep varchar2 := ‘,‘ ) return TYPE_SPLIT pipelined is l_idx pls_integer; v_list varchar2(4000) := p_list; v_num number(18,0) := 1; o_TABLESPLIT OBJ_TABLESPLIT ; begin loop
l_idx := instr(v_list,p_sep); if l_idx > 0 then
o_TABLESPLIT := OBJ_TABLESPLIT(v_num,substr(v_list,1,l_idx-1)); pipe row(o_TABLESPLIT); v_list := substr(v_list,l_idx+length(p_sep)); else o_TABLESPLIT := OBJ_TABLESPLIT(v_num,v_list); pipe row(o_TABLESPLIT); exit; end if; v_num := v_num + 1; end loop; return;
END UFN_SPLIT;
CREATE OR REPLACE TYPE "OBJ_TABLESPLIT" as object
(
sIndex NUMBER(18,0),
sValue varchar2(200)
);
CREATE OR REPLACE TYPE "TYPE_SPLIT" is table of OBJ_TABLESPLIT
oracle 数据库 分割字符串返回结果集函数