[Reprint] Oracle Str Split Function

Source: Internet
Author: 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, Please split in varchar) return tb_strSplit PIPELINED
As
V_tmp varchar2 (4000 );
V_element varchar2 (4000 );
Begin

V_tmp: = inVStr;
While instr (v_tmp, batch split)> 0 loop
V_element: = substr (v_tmp, 1, instr (v_tmp, shard split)-1 );
V_tmp: = substr (v_tmp, instr (v_tmp, 1_split) + length (1_split), length (v_tmp ));
Pipe row (v_element );
End loop;

Pipe row (v_tmp );

Return;
End strToTb;
/

Select * from table (strToTb ('a | B | c ',' | '));

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.