How do I query an Oracle database to display the names of all tables in it?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
Querying
user_tables
anddba_tables
didn't work.This one did:
Simple query to select the tables for the current user:
For better viewing with
sqlplus
If you're using
sqlplus
you may want to first set up a few parameters for nicer viewing if your columns are getting mangled (these variables should not persist after you exit yoursqlplus
session ):Show All Tables
You can then use something like this to see all table names:
Show Tables You Own
As @Justin Cave mentions, you can use this to show only tables that you own:
Don't Forget about Views
Keep in mind that some "tables" may actually be "views" so you can also try running something like:
The Results
This should yield something that looks fairly acceptable like:
Try the below data dictionary views.
This is 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 theSELECT ANY DICTIONARY
privilege or theSELECT_CATALOG_ROLE
role (either of which would allow you to query any data dictionary table). Of course, you may want to exclude certain schemas likeSYS
andSYSTEM
which have large numbers of Oracle tables that you probably don't care about.Alternatively, if you do not have access to
DBA_TABLES
, you can see all the tables that your account has access to through theALL_TABLES
view:Although, that may be a subset of the tables available in the database (
ALL_TABLES
shows you the information for all the tables that your user has been granted access to).If you are only concerned with the tables that you own, not those that you have access to, you could use
USER_TABLES
:Since
USER_TABLES
only has information about the tables that you own, it does not have anOWNER
column – the owner, by definition, is you.Oracle also has a number of legacy data dictionary views--
TAB
,DICT
,TABS
, andCAT
for example-- that could be used. In general, I would not suggest using these legacy views unless you absolutely need to backport your scripts to Oracle 6. Oracle has not changed these views in a long time so they often have problems with newer types of objects. For example, theTAB
andCAT
views both show information about tables that are in the user's recycle bin while the[DBA|ALL|USER]_TABLES
views all filter those out.CAT
also shows information about materialized view logs with aTABLE_TYPE
of "TABLE" which is unlikely to be what you really want.DICT
combines tables and synonyms and doesn't tell you who owns the object.----------------OR------------------
----------------OR------------------