如何查询Oracle数据库以显示Oracle数据库中所有表的名称?
当前回答
查询user_tables和dba_tables无效。 这一个做到了:
select table_name from all_tables
其他回答
为了更好地使用sqlplus查看
如果您正在使用sqlplus,您可能希望首先设置一些参数以更好地查看您的列(这些变量不应该在退出sqlplus会话后继续存在):
set colsep '|'
set linesize 167
set pagesize 30
set pagesize 1000
显示所有表格
然后你可以使用类似这样的东西来查看所有表名:
SELECT table_name, owner, tablespace_name FROM all_tables;
展示你拥有的桌子
正如@Justin Cave提到的,你可以用它来显示你拥有的表:
SELECT table_name FROM user_tables;
不要忘记视图
请记住,一些“表”可能实际上是“视图”,所以你也可以尝试运行类似的程序:
SELECT view_name FROM all_views;
结果
这应该会产生一些看起来相当可以接受的东西,比如:
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中选择,其中列出了当前用户拥有的表。
包括视图:
SELECT owner, table_name as table_view
FROM dba_tables
UNION ALL
SELECT owner, view_name as table_view
FROM DBA_VIEWS
select * from all_all_tables
开头附加的“all”给出了额外的3列,分别是:
OBJECT_ID_TYPE
TABLE_TYPE_OWNER
TABLE_TYPE
推荐文章
- LEFT OUTER JOIN如何返回比左表中存在的记录更多的记录?
- 如何用SQL语句计算百分比
- Postgres唯一约束与索引
- SQL Server动态PIVOT查询?
- MySQL对重复键更新在一个查询中插入多行
- 向现有表添加主键
- 使用电子邮件地址为主键?
- MySQL:如何复制行,但改变几个字段?
- 不能删除或更新父行:外键约束失败
- MongoDB在v4之前不兼容ACID意味着什么?
- SQL WHERE ID IN (id1, id2,…idn)
- 最常见的SQL反模式是什么?
- 错误:没有唯一的约束匹配给定的键引用表"bar"
- 如何使用新的PostgreSQL JSON数据类型中的字段进行查询?
- 分组限制在PostgreSQL:显示每组的前N行?