Oracle character Split function, returns the result set

Source: Internet
Author: User

Oracle cannot support directly returning a table type like MSSQL, so create a custom type first. This is used for nested tables (Nested table).

--Nested tablecreate or replace TYPE split_str is TABLE of VARCHAR,/--functioncreate or replace FUNCTION fn_split (    P_str VARCHAR2, P_delimiter VARCHAR2) RETURN split_str pipelinedas v_str VARCHAR (4000): = P_STR;    V_index number; V_sublength number; BEGIN--P_delimiter is null IF p_delimiter are null then for x in 1..LENGTH (V_STR) LOOP PIP        E ROW (SUBSTR (v_str,x,1));        END LOOP;    RETURN;       END IF;    V_index: = INSTR (V_str,p_delimiter);        While V_index <> 0 LOOP PIPE ROW (SUBSTR (v_str,1,v_index-1));        V_sublength: = Length (V_STR)-(V_index + length (p_delimiter)-1);        V_STR: = SUBSTR (v_str,-v_sublength,v_sublength);    V_index: = INSTR (V_str,p_delimiter);    END LOOP;    PIPE ROW (V_STR); RETURN; end;/--(second way better) SELECT fn_split (' [email protected]@[email protected] @it ', ' @@ ') from dual; SELECT * from Table (Fn_split (' [email protected]@[email protected] @it ', ' @@ '));

From: The teacher of ignorance

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.