Oracle's method of converting a particular delimited string into a table (for cursor-like traversal) ____oracle

Source: Internet
Author: User
CREATE OR REPLACE TYPE ty_object as OBJECT (Col_name VARCHAR2);
/
CREATE OR REPLACE TYPE ty_table as TABLE of Ty_object;
/
CREATE OR REPLACE FUNCTION str2table (v_str       in VARCHAR2,
                                     v_delimiter in VARCHAR2)
-- The purpose of this function is to convert a string separated by a particular character into a cursor, as an example of traversing the cursor return
 ty_table as
  v_ty_table ty_table;
BEGIN
  SELECT ty_object (regexp_substr v_str,
                                 ' [^ ' | V_delimiter | | ']+ ',
                                 1, Level
                                 ,
                                 ' i ')
    BULK COLLECT to
    v_ty_table from
    DUAL
  CONNECT by level <=
             Length (v_str)-
             Length (Regexp_replace (v_str, ' | | V_delimiter | | ",") + 1;
  return v_ty_table;
End;
/
--Application Sample
SELECT * from TABLE (str2table (' 1,2,3 ', ', '))
; /

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.