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:
id | col1 | col2 | col3 | col4 |
---|
1 | first_name | last_name | user_id | user_name |
2 | emp_name | emp_username | emp_id | emp_last_name |
Then, I need to create one table, say dest_1 as follows
first_name | last_name | user_id | user_name |
---|
| | | |
and the other table say dest_2 should be like this:
emp_name | emp_username | emp_id | emp_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).