Convert columns to rows.
Posted on 2004-08-20
I have 2 tables in Oracle:
The columns of DATA_TABLE are as follows:
The columns of DETAIL_TABLE are as follows:
Now suppose the data in DATA_TABLE is as follows:
DT1 DT2 DT3 DT4
1 2 3 4
How do i retrieve and insert the above in DETAIL_TABLE as follows?:
One way of solving this is to loop through the columns in DATA_TABLE and in each loop pick up the value of the column and insert the same to the DETAIL_TABLE.
But this would mean, keeping the above exmaple in mind, that the DATA_TABLE will be queried 4 times and it will involve 4 inserts in DETAIL_TABLE.
Can't this be done using 1 query and 1 insert?