Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select all table names from Oracle DB [duplicate]

Tags:

c#

sql

oracle

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"
like image 933
Sam Avatar asked Oct 05 '22 19:10

Sam


2 Answers

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;
like image 142
peterm Avatar answered Oct 10 '22 03:10

peterm


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

like image 38
a_horse_with_no_name Avatar answered Oct 10 '22 03:10

a_horse_with_no_name