oracle的split函數

來源:互聯網
上載者:User

標籤:

PL/SQL 中沒有split函數,需要自己寫。

  代碼:

 

create or replace type type_split as table of varchar2(50);  --建立一個  type  ,如果為了使split函數具有通用性,請將其size 設大些。

--建立function

create or replace function split

(

   p_list varchar2,

   p_sep varchar2 := ‘,‘

)  return type_split pipelined

 is

   l_idx  pls_integer;

   v_list  varchar2(50) := p_list;

begin

   loop

      l_idx := instr(v_list,p_sep);

      if l_idx > 0 then

          pipe row(substr(v_list,1,l_idx-1));

          v_list := substr(v_list,l_idx+length(p_sep));

      else

          pipe row(v_list);

          exit;

      end if;

   end loop;

   return;

end split;

測試:

 

SQL> select * from table(split(‘northsnow,塞北的雪‘,‘,‘));

COLUMN_VALUE

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

northsnow

塞北的雪

SQL> 


補充:
-----PIPELINED關鍵字是什麼意思?
---- pipe row是什麼意思?

pipelined聲名此function是pipe的,如果這麼聲名了,就必須使用pipe row的方式把資料返回,常規函數最後的"return 變數",就變成了"return".

pipelined的function主要是為了提高效率,不用等所有的資料都處理完成了才返回用戶端,它是邊處理邊返回.適用於大資料量的互動. 

oracle的split函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.