Oracle split Function

Source: Internet
Author: User
PLSQL does not have the split function. You need to write it yourself. Code: createorreplacetypetype_splitastableofvarchar2 (50); -- create a type. To make the split function more universal, set the size to a greater value. -- Create functioncreateorreplacefunctionsplit (p_listvarchar2, p_sepvarchar2:

PL/SQL does not contain the split function. You need to write it yourself. Code: createorreplacetypetype_splitastableofvarchar2 (50); -- create a type. To make the split function more universal, set the size to a greater value. -- CREATE function createorreplacefunctionsplit (p_listvarchar2, p_sepvarchar2:

PL/SQL does not contain the split function. You need to write it yourself.

Code:

Create or replace type type_split as table of varchar2 (50); -- create a type. To make the split function more universal, set the size to a higher value.

-- Create a function

Create or replace function split

(

P_list varchar2,

P_sep varchar2: = ','

) Return type_split pipelined

Is

Rochelle idx pls_integer;

V_list varchar2 (50): = p_list;

Begin

Loop

Rochelle 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, xue ',','));

COLUMN_VALUE

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

Northsnow

Snow in Sebei

SQL>


Supplement:
----- What does the PIPELINED keyword mean?
---- What does pipe row mean?

Pipelined indicates that this function is pipe. If it is so famous, you must use the pipe row Method to return data. The "return variable" at the end of the conventional function becomes "return ".

The pipelined function is mainly used to improve efficiency and return to the client without waiting for all the data to be processed. It is used to process and return while processing, and is suitable for interactions with large data volumes.

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.