Much like these questions:
MSSQL Create Temporary Table whose columns names are obtained from row values of another table
Create a table with column names derived from row values of another table
I need to do the same thing with Oracle, but i also need to fill this new table with data from another table which is organized in a particular way. An Example:
Table Users
|id|name |
----------
|1 |admin|
|2 |user |
Table user_data_cols
|id|field_name|field_description|
---------------------------------
|1 |age |Your age |
|2 |children |Your children |
Table user_data_rows
|id|user_id|col_id|field_value|
-------------------------------
|1 |1 |1 |32 |
|2 |1 |2 |1 |
|3 |2 |1 |19 |
|4 |2 |2 |0 |
What i want is to create, using only sql, a table like this:
|user_id|age|children|
----------------------
|1 |32 |1 |
|2 |19 |0 |
Starting from the data in the other tables (which might change with time so i'll need to create a new table if a new field is added) Is such a thing even possible? I feel this might be against a lot of good practices but it can't be helped...