Let me see if I understand you... Suppose you start with a table
Code:
table t1
c1 | c2 | c3
------------------------
111 | xyz, def | a, b, c
You want to write some generic code that will create a new table and populate it with the normalized version of table t1, right?
That seems like a straightforward solution.
First create an empty clone of the table:
Code:
create table t2 as select * from t1 where 1 = 2;
Then loop through a cursor of t1, and explode each column value into an array based on the comma delimiter (this is just pseudocode to see if I understand you; it won't work anywhere):
Code:
cursor SELECT * FROM t1;
for each row in cursor
{
c2_array = split( c2 using ',' as delimiter);
for each c2_item in c2_array
{
c3_array = split( c3 using ',' as delimiter);
for each c3_item in c3_array
{
INSERT INTO t2 (c1,c2,c3) VALUES (c1, c2_item, c3_item);
}
}
}
If you don't know how many columns are in t1 before you process it, you could consult the data dictionary of the RDBMS you are using (USER_COLUMNS view in Oracle, information_schema.columns in MySQL, etc.) and loop through the table columns based on that.
But I feel like I may have missed the point of your question. Does this help?