5

I write a program which scans all tablenames of a database and displays all

My Db has the Tables : User, Order,History

It should look like this:" Existing Tables: User Order History"

how should the command look like?

string SqlOrder="Select ??? from TestDB"
C8H10N4O2
  • 18,312
  • 8
  • 98
  • 134
Sam
  • 77
  • 5

2 Answers2

3

Try this

SELECT 'Existing Tables: ' || wm_concat(table_name) tablenames 
  FROM user_tables;

For the sample Oracle HR database it returns

TABLENAMES
------------------------------------------------------------------------------------
Existing Tables: REGIONS,LOCATIONS,DEPARTMENTS,JOBS,EMPLOYEES,JOB_HISTORY,COUNTRIES

UPDATE: Example with LISTAGG()

SELECT 'Existing Tables: ' || LISTAGG(table_name, ',') 
        WITHIN GROUP (ORDER BY table_name) tablenames 
  FROM user_tables;
peterm
  • 91,357
  • 15
  • 148
  • 157
1
select table_name
from all_tables

More details in the manual: http://docs.oracle.com/cd/E11882_01/server.112/e25513/statviews_2117.htm#i1592091

  • manual link is missing, besides i guess the OP didnt mean this – CloudyMarble Mar 06 '13 at 09:29
  • I understood it like he would like to have the string before the tablenames and the tablenames as coma separated which would explain tagging the question with the C# tag. – CloudyMarble Mar 06 '13 at 09:32
  • @TwoMore: but he still neeeds to select all table names somehow. –  Mar 06 '13 at 09:33
  • absolutly right, i have no problem with your answer but wonders if it answers the question, guess we will have to wait for the OP – CloudyMarble Mar 06 '13 at 09:35