I have database table. As I further saw that the data was in a particular format. How to perform the following transformation without creating temporary table directly using query?col2 is not static field X and Y it is dynamically determined i.e no of columns is dynamic.

I have database table. As I further saw that the data was in a
Share
You did not specify which version of Oracle you are using so here are a few solutions.
If you are using Oracle 11g+, then you have access to the
PIVOTfunction:See SQL Fiddle with Demo
If you are using another version of Oracle, then you can use an aggregate function with a
CASEstatement:See SQL Fiddle with Demo
If you have an unknown number of
col2values, then you can create a procedure in oracle to generate dynamic sql:Then to execute it:
And the result, should be the same: