It will be converted to a function to display data rows with comma-delimited columns of data in a row

Source: Internet
Author: User

<pre name= "code" class= "SQL" > This is a case of a select To_number (strvalue) as Value from table (' Fn_split ', ', ') using the string cut function ) Select To_char (strvalue) as Value from table (Fn_split (' aa,bb,cc ', ', '))
</pre><pre name= "code" class= "SQL" > Functions:
</pre><pre name= "code" class= "SQL" >create OR REPLACE FUNCTION root.fn_split (p_str in VARCHAR2, P_deli  Miter in VARCHAR2) RETURN Ty_tbl_str_split is j INT: = 0;  I INT: = 1;  -The length of the source string being cut.  Len INT: = 0;  --separates the length of the string len1 INT: = 0;  -The text information for each cell in the middle of the staging.  STR VARCHAR2 (4000);  --Expected return results. Str_split Ty_tbl_str_split: = Ty_tbl_str_split ();  BEGIN-The length of the source string being cut.  Len: = LENGTH (P_STR);  --separates the length of the string.   Len1: = LENGTH (P_delimiter);  --traverse the source string being cut.    While J < Len LOOP--queries the delimited string in the source string being cut.     J: = INSTR (P_str, P_delimiter, i);      IF j = 0 Then-j=0 means not found.      --can be understood as a query to the last unit.      --Set J: = Len, so that the external loop processing can end.      J: = Len;      --Gets the contents of the last cell.      str: = SUBSTR (P_str, i);      --Adds a row to the result. Str_split.      EXTEND;      --Set the result content. Str_split (Str_split.       COUNT): = ty_row_str_split (strvalue = str);      IF i >= Len then EXIT;    END IF; ELSE--assumed to be in the source string being cut.      A delimited string was found. --First.  Gets the content of the cut.    str: = SUBSTR (P_str, I, j-i); --then set the index. Next time you look for it again.      Start at the specified index (not from 0) I: = j + len1;      --Add a good result. Str_split.      EXTEND;      --the contents of the result set. Str_split (Str_split.    COUNT): = ty_row_str_split (strvalue = str);  END IF;    END LOOP; RETURN Str_split; END Fn_split;

It will be converted to a function to display data rows with comma-delimited columns of data in a row

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.