You can use a combination of Oracle's string manipulation functions and a hierarchical query to achieve this. Below is a step-by-step example to help you understand how to split comma-separated values in a column into multiple rows.


Assuming you have a table named `cusip_table` and a column named `cusip`:


CREATE TABLE cusip_table (id NUMBER, cusip VARCHAR2(50));


INSERT INTO cusip_table VALUES (1, '12345,67890,ABCDEF');

INSERT INTO cusip_table VALUES (2, '54321,X9876,Y5432');

INSERT INTO cusip_table VALUES (3, 'Z1234');


You can use the following SQL query to split the `cusip` column into multiple rows:

SELECT id, 

       TRIM(REGEXP_SUBSTR(cusip, '[^,]+', 1, LEVEL)) AS single_cusip

FROM   cusip_table

CONNECT BY PRIOR id = id

       AND PRIOR DBMS_RANDOM.VALUE IS NOT NULL

       AND LEVEL <= REGEXP_COUNT(cusip, '[^,]+') + 1

ORDER BY id, LEVEL;


In this query:

- `REGEXP_SUBSTR(cusip, '[^,]+', 1, LEVEL)`: This function is used to split the comma-separated values. It returns the substring from `cusip` that matches the regular expression '[^,]+', which means "one or more characters that are not a comma". The fourth parameter, `LEVEL`, specifies which occurrence of the substring to return.

- `CONNECT BY PRIOR id = id AND PRIOR DBMS_RANDOM.VALUE IS NOT NULL AND LEVEL <= REGEXP_COUNT(cusip, '[^,]+') + 1`: This is a hierarchical query clause that is used to generate the multiple rows. `LEVEL` is an Oracle pseudo column that returns the level number of a node in a tree structure. The `CONNECT BY` clause is saying to generate rows while the `LEVEL` is less than or equal to the number of elements in the comma-separated list.

- `TRIM`: This function is used to remove any leading or trailing spaces from the substrings.

- `ORDER BY id, LEVEL`: This is used to order the result set first by `id`, and then by `LEVEL` to maintain the original order of elements in the comma-separated list.

Please adjust the table name, column name, and any other parts of the query as needed to fit your specific use case.

If your dataset doesn't have a unique identifier for each row, you can still split the comma-separated values in the `CUSIP` column into multiple rows. You would essentially treat each row as its own dataset for the purposes of splitting the values.


Assuming you have a table named `cusip_table` and a column named `cusip`, and you want to duplicate the entire row of data for each CUSIP value:


CREATE TABLE cusip_table (other_column VARCHAR2(50), cusip VARCHAR2(50));


INSERT INTO cusip_table VALUES ('data1', '12345,67890,ABCDEF');

INSERT INTO cusip_table VALUES ('data2', '54321,X9876,Y5432');

INSERT INTO cusip_table VALUES ('data3', 'Z1234');


You can use the following SQL query to split the `cusip` column into multiple rows:

SELECT other_column,

       TRIM(REGEXP_SUBSTR(cusip, '[^,]+', 1, LEVEL)) AS single_cusip

FROM   cusip_table

CONNECT BY REGEXP_SUBSTR(cusip, '[^,]+', 1, LEVEL) IS NOT NULL

       AND PRIOR cusip = cusip

       AND PRIOR sys_guid() IS NOT NULL

ORDER BY other_column, LEVEL;


In this query:

- `REGEXP SUBSTR(cusip, '[^,]+', 1, LEVEL)`: This function is used to split the comma-separated values. It returns the substring from `cusip` that matches the regular expression '[^,]+', which means "one or more characters that are not a comma". The fourth parameter, `LEVEL`, specifies which occurrence of the substring to return.

- `CONNECT BY REGEXP_SUBSTR(cusip, '[^,]+', 1, LEVEL) IS NOT NULL AND PRIOR cusip = cusip AND PRIOR sys_guid() IS NOT NULL`: This is a hierarchical query clause that is used to generate the multiple rows. The `CONNECT BY` clause is saying to generate rows while there are still substrings to be returned by `REGEXP_SUBSTR`.

- `TRIM`: This function is used to remove any leading or trailing spaces from the substrings.

- `ORDER BY other_column, LEVEL`: This is used to order the result set first by `other_column`, and then by `LEVEL` to maintain the original order of elements in the comma-separated list.

The `PRIOR sys_guid()` part of the `CONNECT BY` clause is used to make each row in the result set treated independently, as there's no unique identifier for each row.

Please adjust the table name, column name, and any other parts of the query as needed to fit your specific use case.