Search code examples
sqloracle-databaseoracle11glistagg

Get all of the columns name and fetch them into one row


So, i know i can select COLUMN names with the query:

SELECT column_name FROM ALL_TAB_COLS WHERE table_name = 'MY_TABLE_NAME'

It's working fine, if i use rownum = 1...

OUTPUT: sz.price

I have to use it, because it's a query in EAS(Enterprise software). If i dont use it -> subquery returns more than one row

How can i get all the columns name which are in MY_TABLE_NAME fetch into one row ?

expected OUTPUT: sz.price, sz.column2, sz.column3, ....

Version: Oracle Database 11g Release 11.2.0.4.0


Solution

  • you can use listagg

    select listagg(column_name, ',' )  within group (order by column_name) as "columns"
      from all_tab_columns
     where table_name = 'MY_TABLE_NAME';