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
  • 16,948
  • 6
  • 87
  • 123
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;
a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
peterm
  • 88,818
  • 14
  • 143
  • 153
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

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843