Oracle's Split function

Source: Internet
Author: User

There is no split function in PL/SQL and you need to write it yourself.

Code:

Create or replace type Type_split as Table of VARCHAR2 (50); --Create a type, and if you want the split function to be generic, set its size larger.

--Create function

Create or Replace function split

(

P_list VARCHAR2,

P_sep varchar2: = ', '

) Return Type_split pipelined

Is

L_idx Pls_integer;

V_list varchar2 (): = 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;

Test:

Sql> select * FROM table (Split (' Northsnow, Saibei Snow ', ', '));

Column_value

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

Northsnow

Saibei of Snow

Sql>


Add:
What do-----pipelined keywords mean?
What do you mean by----pipe row?

Pipelined reputation This function is pipe, if so famous, you must use pipe row to return the data, the general function of the last "return variable", it becomes "return".

The function of pipelined is mainly to improve the efficiency, do not wait for all the data to be processed before returning to the client, it is the edge processing side return. For interactions with large data volumes.

Oracle's Split function

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.