Oracle | String splitting function

Source: Internet
Author: User

/** * string Split function. * @param p_str The string to be split * @param delimiter * @return Custom table type Ty_str_split. *       Use the method select Column_value from table (Fn_split (', ', ')) * @Author: Xder */create OR REPLACE FUNCTION fn_split (p_str  In VARCHAR2, P_delimiter in VARCHAR2) RETURN Ty_str_split is J INT: = 0;  I INT: = 1;  LEN INT: = 0;  LEN1 INT: = 0;  STR VARCHAR2 (4000); Str_split Ty_str_split: = Ty_str_split ();  BEGIN LEN: = LENGTH (P_STR);  LEN1: = LENGTH (P_delimiter);    While J < LEN LOOP J: = INSTR (P_str, P_delimiter, I);      IF j = 0 Then J: = LEN;      STR: = SUBSTR (P_str, I); Str_split.      EXTEND; Str_split (Str_split.      COUNT): = STR;      IF I >= LEN then EXIT;    END IF;      ELSE STR: = SUBSTR (P_str, I, j-i);      I: = J + LEN1; Str_split.      EXTEND; Str_split (Str_split.    COUNT): = STR;  END IF;  END LOOP; RETURN Str_split; END Fn_split; 

  

/** * String splitting function. * @param p_str The string to be split * @param delimiter * @return Custom table type Ty_str_split.       * How to use Select Column_value from table (Fn_split (', ', ')) * @Author: Xder */create OR REPLACE FUNCTION fn_split (p_str  In VARCHAR2, P_delimiter in VARCHAR2) RETURN Ty_str_split is J INT: = 0;  I INT: = 1;  LEN INT: = 0;  LEN1 INT: = 0;  STR VARCHAR2 (4000); Str_split Ty_str_split: = Ty_str_split ();  BEGIN LEN: = LENGTH (P_STR); LEN1: = LENGTH (P_delimiter);
While J < LEN LOOP J: = INSTR (P_str, P_delimiter, I);
IF j = 0 Then J: = LEN;      STR: = SUBSTR (P_str, I); Str_split.      EXTEND; Str_split (Str_split. COUNT): = STR;
IF I >= LEN then EXIT;    END IF;      ELSE STR: = SUBSTR (P_str, I, j-i);      I: = J + LEN1; Str_split.      EXTEND; Str_split (Str_split.    COUNT): = STR;  END IF; END LOOP;
RETURN Str_split; END Fn_split;

Oracle | String splitting 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.