如何查询Oracle数据库以显示Oracle数据库中所有表的名称?
当前回答
我们可以从下面的查询中获得所有的表,包括列的详细信息:
SELECT * FROM user_tab_columns;
其他回答
select object_name from user_objects where object_type='TABLE';
---------------- 或 ------------------
select * from tab;
---------------- 或 ------------------
select table_name from user_tables;
select * from all_all_tables
开头附加的“all”给出了额外的3列,分别是:
OBJECT_ID_TYPE
TABLE_TYPE_OWNER
TABLE_TYPE
下面是一个注释的SQL查询片段,描述了如何使用选项:
-- need to have select catalog role
SELECT * FROM dba_tables;
-- to see tables of your schema
SELECT * FROM user_tables;
-- tables inside your schema and tables of other schema which you possess select grants on
SELECT * FROM all_tables;
您可以使用Oracle数据字典来获取Oracle对象的信息。
你可以通过不同的方式获取表列表:
select *
from dba_tables
或者举个例子:
select *
from dba_objects
where object_type = 'TABLE'
然后你可以使用表名获取表列:
select *
from dba_tab_columns
然后你可以得到依赖项列表(触发器,视图等):
select *
from dba_dependencies
where referenced_type='TABLE' and referenced_name=:t_name
然后你可以得到这个对象的文本源:
select * from dba_source
如果您愿意,可以使用USER或ALL视图而不是DBA视图。
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.
推荐文章
- 如何在Ruby On Rails中使用NuoDB手动执行SQL命令
- 查询JSON类型内的数组元素
- 确定记录是否存在的最快方法
- 获得PostgreSQL数据库中当前连接数的正确查询
- 在SQL选择语句Order By 1的目的是什么?
- 我如何循环通过一组记录在SQL Server?
- 如何从命令行通过mysql运行一个查询?
- 外键约束可能导致循环或多条级联路径?
- 使用LIMIT/OFFSET运行查询,还可以获得总行数
- 当恢复sql时,psql无效命令\N
- ORA-12505, TNS:监听器当前不知道连接描述符中给定的SID
- 货币应该使用哪种数据类型?
- 如何选择每一行的列值不是独特的
- 如何改变字符集(和排序)在整个数据库?
- mySQL:: insert到表,数据从另一个表?