Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Create table where columns' names are the values of another table's row

Hawk333Dec 8 2015 — edited Dec 9 2015

I need to create a table dynamically (dest_xx) using EXECUTE IMMEDIATE. The table will have various number of columns. Basically the columns names should be taken from another table values (tab_src).

For example if tab_src is as follows:

idcol1col2col3col4
1first_namelast_nameuser_iduser_name
2emp_nameemp_usernameemp_idemp_last_name

Then, I need to create one table, say dest_1 as follows

first_namelast_nameuser_iduser_name

and the other table say dest_2 should be like this:

emp_nameemp_usernameemp_idemp_last_name

How can I achieve that?

All what I found on the web is just about how create table from another table structure, or using execute immediate with variables rather than columns values.

The source table has 100 columns, but the destination tables could have any number of columns up to 100 (only not null columns in the source will be created).

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 6 2016
Added on Dec 8 2015
11 comments
630 views