[轉載]Oracle Str Split Function

來源:互聯網
上載者:User

create or replace type tb_strSplit  as table of varchar2(4000);

create or replace function to_table(pv_str varchar2,pv_split varchar2) return tb_strSplit
as
  ltab tb_strSplit := tb_strSplit();
  pos integer := 0;
  ls varchar2(4000) := pv_str;
begin
  pos := instr(ls,pv_split);
  while pos > 0 loop
    ltab.extend;
    ltab(ltab.count) := substr(ls,1,pos - 1);
    ls := substr(ls,pos + length(pv_split));
    pos := instr(ls,pv_split);
  end loop;
  ltab.extend;
  ltab(ltab.count) := ls;
  return ltab;
end;

set serverout on
declare
aa tbl_str;
begin
aa := to_table('a|||b|||c','|||');
for i in 1..aa.count loop
        dbms_output.put_line(aa(i));
end loop;
end;
/

----------------------------------------------------------

CREATE OR REPLACE function strToTb(inVStr in string,inStrSplit in varchar) return tb_strSplit PIPELINED
as
v_tmp varchar2(4000);
v_element varchar2(4000);
begin

v_tmp := inVStr;
while instr(v_tmp,inStrSplit)>0 loop
   v_element := substr(v_tmp,1,instr(v_tmp,inStrSplit)-1);
   v_tmp := substr(v_tmp,instr(v_tmp,inStrSplit)+length(inStrSplit),length(v_tmp));
   pipe row(v_element);
end loop;

pipe row(v_tmp);

return;
end strToTb;
/

select * from table(strToTb('a|||b|||c','|||'));

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.