tags:

views:

35661

answers:

13

How do I query an Oracle database to display the names of all tables in it?

+19  A: 
SELECT owner, table_name
  FROM dba_tables

assuming that you have access to the DBA_TABLES data dictionary view. If you do not have those privileges but need them, you can request that the DBA explicitly grants you privileges on that table or that the DBA grants you the SELECT ANY DICTIONARY privilege or the SELECT_CATALOG_ROLE role either of which would allow you to query any data dictionary table. Of course, you may want to exclude certain schemas like SYS and SYSTEM which have large numbers of tables that you probably don't care about because those are all delivered by Oracle.

If you do not have access to DBA_TABLES, you can see all the tables that your account has access to through the ALL_TABLES view

SELECT owner, table_name
  FROM all_tables

although that may be a subset of the tables available in the database

Justin Cave
I'm getting an exception "ORA-00942: table or view does not exist"
vitule
Then you haven't been given permission to see all the tables in the database. You can query the ALL_TABLES data dictionary view to see all the tables you are allowed to access, which may be a small subset of the tables in the database.
Justin Cave
@Justin: Thanks. I wrote my own answer at the same time you wrote this comment. I'm accepting your answer.
vitule
+1  A: 

Try selecting from user_tables which lists the tables owned by the current user.

EddieAwad
+2  A: 

Querying user_tables and dba_tables didn't work.
This one did:

select table_name from all_tables
vitule
For a more complete answer, see the accepted answer **including** the comments.
vitule
A: 
select table_name from tabs;
A: 
SELECT * FROM USER_TABLESPACES
+1  A: 

select * from tabs;

shorter version...

Firstthumb
+2  A: 

Going one step further, there is another view called cols (all_tab_columns) which can be used to ascertain which tables contain a given column name.

For example:

SELECT table_name, column_name
FROM cols
WHERE table_name LIKE 'EST%'
AND column_name LIKE '%CALLREF%';

to find all tables having a name beginning with EST and columns containing CALLREF anywhere in their names.

This can help when working out what columns you want to join on, for example, depending on your table and column naming conventions.

stealth_angoid
+1  A: 

select * from tab;

also shorter

A: 

Thanks :) select table_name froma all_tables is great :)

Dzorg
A: 

Once I've gotten the names of the tables, is there an easy way to loop through them and do a 'describe' on each table having the output show up either on screen or in a spool file?

Greg
A: 

the select table_name from all_tables does not work in sql 2005

vikas garg
A: 

select * from cat;

Devendiran
A: 

select * from dict;

aay