Oracle character separation function (split)

Source: Internet
Author: User

To allow PL/SQL functions to return multiple rows of data, a ref cursor or a data set must be returned. Ref cursor is limited to the data that can be selected from the query. The entire set must be specific before it can be returned. Oracle 9i corrected the latter situation through the introduced pipeline table function. A table function is a function that returns the entire row set (usually as a set). It can be queried directly from an SQL statement, just as if it is a real database table. Pipeline table functions are similar, but they return data as they are during build, rather than all at once. Pipeline table functions are more effective because data can be returned as quickly as possible.

The canonicalized table function must return a set. In a function, the pipe row statement is used to return a single element of the set. The function must end with an empty return statement to indicate that it has been completed. Once we create the above function, we can use the table operator to call it from SQL queries.

Pipeline table functions are often used to convert data from one type to another.

 Create   Or   Replace   Function Strsplit (p_value Varchar2  , P_split  Varchar2 :=   '  ,  '  )  --  Usage: Select * from table (strsplit ('1, 2, 3, 4, 5 '))   Return  Strsplit_type pipelined  Is  V_idx  Integer  ; V_str  Varchar2 ( 500 ); V_strs_last  Varchar2 ( 4000 ): =  P_value;  Begin  Loop v_idx:  =  Instr (v_strs_last, p_split );  Exit   When V_idx =   0  ; V_str:  = Substr (v_strs_last, 1 , V_idx -   1  ); V_strs_last:  = Substr (v_strs_last, v_idx +   1  );  Pipe  Row (v_str );  End  Loop;  Pipe  Row (v_strs_last ); Return  ;  End Strsplit;
 
Usage: Select * from table (strsplit ('1, 2, 3, 4, 5 '))

1 1
22
33
44
55

 



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.