6

I would like to know how it is possible to list all the tables and columns from my ORACLE database but by "grouping" all this information into only one table? A table with two columns: one with the name of the table and the other one with all the colums in that table. Thank you.

For instance:

TABLE_NAME COLUMNS

TABLE A => LIST OF COLUMNS

TABLE B => LIST OF COLUMNS

TABLE C => LIST OF COLUMNS

This is how I list all the tables from my ORACLE database:

SELECT TABLE_NAME FROM USER_TABLES;

This is how I list all the columns from one of the tables from my ORACLE database:

SELECT column_name
FROM user_tab_cols
WHERE table_name = 'TABLE_NAME';
5
  • 5
    what's wrong with user_tab_cols. you found the 2 columns table_nameand column_name already. so what are you missing? Commented Apr 20, 2016 at 14:55
  • @Ariana: Aツ is right. But if you want to know other info present only in user_tab_cols you can JOIN two tables using table_name field Commented Apr 20, 2016 at 15:01
  • I updated my post. What I want is "grouping" the information of the two selects into one table. Commented Apr 20, 2016 at 15:05
  • Join the tables and order the results by table_name. If you really need a single row for each table, use something more suitable to re-arrange the results. For example, I could do it in 5 minutes using ColdFusion. Commented Apr 20, 2016 at 15:05
  • 1
    looks like your question is not your question. string aggregate oracleis what you should search with your favourite tool. Commented Apr 20, 2016 at 15:14

1 Answer 1

3

Use listagg to get all the column names in a table as a list.

create table table_column_list as 
SELECT table_name,listagg(column_name,',') within group(order by column_id) column_list
FROM user_tab_cols
group by table_name;
Sign up to request clarification or add additional context in comments.

1 Comment

Meanwhile, this is exactly the select I made up. Thanks anyway :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.