oracle 自定义函数splitstr

 

函数主体

create or replace type type_split as table of varchar2(4000)

 

create or replace function splitstr(p_string varchar2,
                                    p_sep    varchar2 := ',')
  return type_split
  pipelined
--dbms_output输出的信息,需要在服务器执行完整个函数后一次性的返回给客户端
  --pipelined 表明这是一个管道函数,oracle管道函数的返回值类型必须为集合
  --PIPE ROW语句被用来返回该集合的单个元素
 as
  v_string varchar2(4000) := p_string;
  idx      Number;
begin
  loop
    --idx为第一个,所在的位置
    idx := instr(v_string, p_sep);
    if idx > 0 then
      --,前面的数据加入Row/,后面的数据为下个循环使用的字符串
      pipe row(substr(v_string, 1, idx - 1));
      v_string := substr(v_string, idx + length(p_sep));
    else
      PIPE ROW(v_string);
      EXIT;
    end if;
  end loop;
  --执行完后需return
  return;
end;

 使用

select * from table(SPLITSTR(PARA1.PROPERTY_VALUE, ','))

 

posted @ 2023-02-03 10:15  小菜鸟大神  阅读(224)  评论(0编辑  收藏  举报