I have a table: Table_1 looks like the following:
id | column1
-----------------
10 | abc, kdm
20 | xyz, lop, nkk
What I want is to convert the table looks like the following:
id | column1
-----------------
10 | abc
10 | kdm
20 | xyz
20 | lop
20 | nkk
To do this, I used a query like this:
select id, regexp_substr(column1,'[^,]+', 1, level) from Table_1
connect by regexp_substr(column1, '[^,]+', 1, level) is not null;
This query works fine as long as the number of comma separated values are less. But when it grows, it consumes more and more time to process.
One solution came to my mind was to create a separate table and then insert values by iterating through the values of Table_1.
Pseudo code as follows:
FOR r in each row
FOR i in 1..length(comma_separated_values)
insert into new_table values(id, select regexp_substr(column1,'[^,]+', 1, i) from Table_1
End LOOP;
End LOOP;
But since this also consumes much time as the comma separated values grows, Is there any other optimal way to do this(preferred not to use another table, but a temporary/virtual table is OK)?
I'm using Oracle SQL.
Thanks in advance.