Oracle Split String function

Source: Internet
Author: User

This function splits the target string with the specified string and returns the result through the table structure. The code is as follows:CREATE OR REPLACETYPE Str_split is TABLE  of VARCHAR2(4000);CREATE OR REPLACE FUNCTIONSplitstr (p_stringinch VARCHAR2, P_delimiterinch VARCHAR2)    RETURNstr_split pipelined asV_length Number:=LENGTH (p_string); V_start Number:= 1; V_index Number;BEGIN     while(V_start<=v_length) LOOP V_index:=INSTR (p_string, P_delimiter, V_start); IFV_index= 0         Then            PIPEROW (SUBSTR (p_string, V_start)); V_start:=V_length+ 1; ELSE            PIPEROW (SUBSTR (p_string, V_start, V_index-V_start)); V_start:=V_index+ 1; END IF; ENDLOOP; RETURN;ENDSplitstr; Once created, let's test it, for example, execute the following sql:Select *  from Table(Splitstr ('hello,cnblogs!',',') , whose output is a two-row table, such as: the-9-9-11.38. theto display rows to columns:SelectA.column_value V1,b.column_value v2 from (Select *  from(SelectRowNum rn,t.*  from Table(Splitstr ('hello,cnblogs!',',')) (t)) A, (Select *  from(SelectRowNum rn,t.*  from Table(Splitstr ('hello,cnblogs!',',')) ( t)) bwhereA.rn=1  andB.rn=2 the-9-9-11.44. -

Oracle Split String function

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.