Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

sql - 获取Oracle中所有表的列表?(Get list of all tables in Oracle?)

如何查询Oracle数据库以显示其中所有表的名称?

  ask by vitule translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
SELECT owner, table_name
  FROM dba_tables

This is assuming that you have access to the DBA_TABLES data dictionary view.

(这假设您可以访问DBA_TABLES数据字典视图。)

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).

(如果您没有这些权限但需要它们,则可以请求DBA明确授予您对该表的权限,或者DBA授予您SELECT ANY DICTIONARY权限或SELECT_CATALOG_ROLE角色(其中任何一个都允许您查询任何数据字典表)。)

Of course, you may want to exclude certain schemas like SYS and SYSTEM which have large numbers of Oracle tables that you probably don't care about.

(当然,您可能希望排除某些模式,如SYSSYSTEM ,这些模式具有您可能不关心的大量Oracle表。)

Alternatively, 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:

(或者,如果您无权访问DBA_TABLES ,则可以通过ALL_TABLES视图查看您的帐户可以访问的所有表:)

SELECT owner, table_name
  FROM all_tables

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).

(虽然,这可能是数据库中可用表的子集( ALL_TABLES显示了您的用户被授予访问权限的所有表的信息)。)

If you are only concerned with the tables that you own, not those that you have access to, you could use USER_TABLES :

(如果您只关心您拥有的表,而不是您有权访问的表,则可以使用USER_TABLES :)

SELECT table_name
  FROM user_tables

Since USER_TABLES only has information about the tables that you own, it does not have an OWNER column – the owner, by definition, is you.

(由于USER_TABLES仅包含您拥有的表的信息,因此它没有OWNER列 - 根据定义,所有者就是您。)

Oracle also has a number of legacy data dictionary views-- TAB , DICT , TABS , and CAT for example-- that could be used.

(甲骨文公司还拥有一批传统数据字典views--的TABDICTTABSCAT的example--可能被使用。)

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.

(一般情况下,我不建议使用这些遗留视图,除非您绝对需要将脚本反向移植到Oracle 6. Oracle在很长一段时间内没有更改这些视图,因此它们经常遇到新类型对象的问题。)

For example, the TAB and CAT 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.

(例如, TABCAT视图都显示有关用户回收站中的表的信息,而[DBA|ALL|USER]_TABLES视图全部过滤掉这些表。)

CAT also shows information about materialized view logs with a TABLE_TYPE of "TABLE" which is unlikely to be what you really want.

(CAT还显示有关TABLE_TYPE为“TABLE”的物化视图日志的信息,这不太可能是您真正想要的。)

DICT combines tables and synonyms and doesn't tell you who owns the object.

(DICT结合了表和同义词,并没有告诉你谁拥有该对象。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...