如何查询Oracle数据库以显示Oracle数据库中所有表的名称?
当前回答
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.
其他回答
更进一步,还有一个名为cols (all_tab_columns)的视图,可用于确定哪些表包含给定的列名。
例如:
SELECT table_name, column_name
FROM cols
WHERE table_name LIKE 'EST%'
AND column_name LIKE '%CALLREF%';
查找名称以EST开头的所有表以及名称中任何位置包含CALLREF的列。
例如,根据表和列的命名约定,这可以帮助确定要连接哪些列。
下面是一个注释的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;
有了这些,你可以选择:
SELECT DISTINCT OWNER, OBJECT_NAME
FROM DBA_OBJECTS
WHERE OBJECT_TYPE = 'TABLE' AND OWNER='SOME_SCHEMA_NAME';
SELECT DISTINCT OWNER, OBJECT_NAME
FROM ALL_OBJECTS
WHERE OBJECT_TYPE = 'TABLE' AND OWNER='SOME_SCHEMA_NAME';
实际上,可以通过SQL查询获得表列表。也可以通过允许生成数据字典的工具来做到这一点,例如ERWIN, Toad data Modeler或ERBuilder。使用这些工具,除了表名之外,您还将拥有字段,它们的类型,对象,如(触发器,序列,域,视图…)
下面的步骤来生成你的表格定义:
您必须对数据库进行逆向工程 在Toad数据建模器中:菜单->文件->逆向工程->逆向工程向导 在ERBuilder数据建模器中:菜单->文件->逆向工程
您的数据库将在软件中显示为实体关系图。
生成包含Tables定义的数据字典 在Toad data modeler中:菜单->模型->生成报告->运行 在ERBuilder数据建模器:菜单->工具->生成模型文档
我找不到一个有用的答案
DBA_ALL_TABLES (ALL_ALL_TABLES/USER_ALL_TABLES)
所以决定加上我的版本。 这个视图实际上返回比DBA_TABLES更多的数据,因为它也返回对象表(http://docs.oracle.com/cd/E11882_01/server.112/e40402/statviews_1003.htm)。
推荐文章
- 选项(RECOMPILE)总是更快;为什么?
- 设置数据库从单用户模式到多用户
- oracle中的RANK()和DENSE_RANK()函数有什么区别?
- 的类型不能用作索引中的键列
- SQL逻辑运算符优先级:And和Or
- 如何检查一个表是否存在于给定的模式中
- 添加一个复合主键
- 如何在SQL Server Management Studio中查看查询历史
- 可以为公共表表达式创建嵌套WITH子句吗?
- 什么时候我需要在Oracle SQL中使用分号vs斜杠?
- SQL Server的NOW()?
- 在SQL中,count(列)和count(*)之间的区别是什么?
- 在SQL Server中截断(不是四舍五入)小数位
- 仅在Datetime列上按日期分组
- PostgreSQL通配符LIKE用于单词列表中的任何一个