Oracle split string function

create or replace type string_table is table of varchar2(2000);
create or replace function splitter(p_string in varchar2,p_delimiter in varchar2)
  return string_table pipelined
as
  --Function: used to split strings
  --用法:select * from table(splitter('wallimn,http://wallimn.iteye.com',','));
  v_length number := length(p_string);
  v_start number:=1;
  v_index number;
begin
  while(v_start<=v_length) loop
    v_index := instr(p_string,p_delimiter,v_start);
    if v_index=0 then
      pipe row(trim(substr(p_string,v_start)));
      v_start := v_length+1;
    else
      pipe row(trim(substr(p_string,v_start,v_index-v_start)));
      v_start:=v_index+1;
    end if;
  end loop;
  
end splitter;


Reference: http://www.cnblogs.com/yudy/archive/2012/07/18/2597874.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327033705&siteId=291194637