如何查询Oracle数据库以显示Oracle数据库中所有表的名称?
当前回答
为当前用户选择表的简单查询:
SELECT table_name FROM user_tables;
其他回答
SELECT owner, table_name
FROM dba_tables
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 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 Oracle tables that you probably don't care about.
或者,如果您没有访问DBA_TABLES,您可以通过ALL_TABLES视图查看您的帐户访问的所有表:
SELECT owner, table_name
FROM all_tables
不过,这可能是数据库中可用表的一个子集(ALL_TABLES显示用户已被授予访问权限的所有表的信息)。
如果你只关心你拥有的表,而不是那些你可以访问的表,你可以使用USER_TABLES:
SELECT table_name
FROM user_tables
因为USER_TABLES只包含关于您拥有的表的信息,所以它没有OWNER列——根据定义,所有者就是您自己。
Oracle also has a number of legacy data dictionary views-- TAB, DICT, TABS, and CAT 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, 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. CAT also shows information about materialized view logs with a TABLE_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.
尝试从user_tables中选择,其中列出了当前用户拥有的表。
查询user_tables和dba_tables无效。 这一个做到了:
select table_name from all_tables
包括视图:
SELECT owner, table_name as table_view
FROM dba_tables
UNION ALL
SELECT owner, view_name as table_view
FROM DBA_VIEWS
更进一步,还有一个名为cols (all_tab_columns)的视图,可用于确定哪些表包含给定的列名。
例如:
SELECT table_name, column_name
FROM cols
WHERE table_name LIKE 'EST%'
AND column_name LIKE '%CALLREF%';
查找名称以EST开头的所有表以及名称中任何位置包含CALLREF的列。
例如,根据表和列的命名约定,这可以帮助确定要连接哪些列。
推荐文章
- 如何在SQL中选择表的最后一条记录?
- SQL在Oracle中连接多行列值的查询
- 在单个查询中计算空值和非空值
- 在存储过程中使用“SET XACT_ABORT ON”有什么好处?
- SQL to LINQ工具
- 如何从一个查询插入多行使用雄辩/流利
- 如何连接列在Postgres选择?
- 有人可以对SQL查询进行版权保护吗?
- 如何知道MySQL表最近一次更新?
- 如何转储一些SQLite3表的数据?
- 如何创建一个SQL Server函数“连接”多行从一个子查询到一个单独的分隔字段?
- 在MySQL中的一个查询中更新多个具有不同值的行
- 在SQL中更新多个列
- 如何删除表中特定列的第一个字符?
- MySQL OR与IN性能