统计Oracle中表的数量

发布于 2024-10-18 03:17:08 字数 173 浏览 3 评论 0原文

就像MySQL有“SHOW TABLES”一样,如何对Oracle DB中的表进行计数。一点点的研究给了我这样的疑问:

select owner, count(*) from dba_tables

那么就像 MySQL 有一个标准命令一样,Oracle 有一个吗?

Like MySQL has "SHOW TABLES" , how do you count tables in Oracle DB. Little bit of research gave me this query:

select owner, count(*) from dba_tables

So like MySQL has a standard command, does Oracle have one?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

奶气 2024-10-25 03:17:08

尝试:

SELECT COUNT(*) FROM USER_TABLES;

好吧,我的机器上没有oracle,我运行mysql(OP评论)

在撰写本文时运行 mysql(OP 注释), 这个网站非常适合测试各种数据库类型。

try:

SELECT COUNT(*) FROM USER_TABLES;

Well i dont have oracle on my machine, i run mysql (OP comment)

at the time of writing, this site was great for testing on a variety of database types.

掐死时间 2024-10-25 03:17:08

是的,您的查询肯定会起作用,只需稍微修改一下即可。请参阅此处:http://download. oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_2105.htm#i1592091

运行此命令:

SELECT TABLE_NAME FROM DBA_TABLES;

获取表列表。

并运行此命令:

SELECT Count(*) FROM DBA_TABLES;

以获取表的数量。

Yeah sure your query will work just modify it a little. Look here for refrence : http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_2105.htm#i1592091

Run this:

SELECT TABLE_NAME FROM DBA_TABLES;

to get list of tables.

and Run this:

SELECT Count(*) FROM DBA_TABLES;

to get the count of tables.

反差帅 2024-10-25 03:17:08

从 all_tables 中选择 count(*),其中owner='schema_name'

Select count(*) FROM all_tables where owner='schema_name'

天邊彩虹 2024-10-25 03:17:08

请在下面找到 - 这是我使用的最简单的一种:

select owner, count(*) from dba_tables group by owner;

Please find below - its the simplest one I use :

select owner, count(*) from dba_tables group by owner;
冷情 2024-10-25 03:17:08

这些文档描述了数据字典视图:

all_tables: http:// docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_4473.htm#REFRN26286

user_tables:http://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_2105.htm#i1592091

dba_tables: http://docs.oracle.com/cd/B19306_01/server.102/ b14237/statviews_4155.htm#i1627762

您可以对这些视图运行查询来计算您需要的内容。

在@Anurag Thakre 的回答中添加更多内容:

使用此查询将为您提供有关的实际计数
业主

SELECT COUNT(*),tablespace_name FROM USER_TABLES group by tablespace_name;

或表所有者:

SELECT COUNT(*), owner  FROM ALL_TABLES group by owner;

表空间本身并不标识唯一的对象所有者。多个用户可以在同一个表空间中创建对象,单个用户可以在不同的表空间中创建对象。
将表和索引分离到不同的表空间中是一种常见的做法。

These documents describe data dictionary views:

all_tables: http://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_4473.htm#REFRN26286

user_tables: http://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_2105.htm#i1592091

dba_tables: http://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_4155.htm#i1627762

You can run queries on these views to count what you need.

To add something more to @Anurag Thakre's answer:

Use this query which will give you the actual no of counts respect to
the owners

SELECT COUNT(*),tablespace_name  FROM USER_TABLES group by tablespace_name;

Or by table owners:

SELECT COUNT(*), owner  FROM ALL_TABLES group by owner;

Tablespace itself does not identify an unique object owner. Multiple users can create objects in the same tablespace and a single user can create objects in various tablespaces.
It is a common practice to separate tables and indexes into different tablespaces.

苯莒 2024-10-25 03:17:08

如果您想要所有者列表以及每个所有者的表数量,请尝试:

    SELECT distinct owner, count(table_name) FROM dba_tables GROUP BY owner;

If you'd like a list of owners, and the count of the number of tables per owner, try:

    SELECT distinct owner, count(table_name) FROM dba_tables GROUP BY owner;
倥絔 2024-10-25 03:17:08

如果你想知道属于某个模式/用户的表的数量,你也可以使用类似于以下的 SQL:

SELECT Count(*) FROM DBA_TABLES where OWNER like 'PART_OF_NAME%';

If you want to know the number of tables that belong to a certain schema/user, you can also use SQL similar to this one:

SELECT Count(*) FROM DBA_TABLES where OWNER like 'PART_OF_NAME%';
在巴黎塔顶看东京樱花 2024-10-25 03:17:08
REM setting current_schema is required as the 2nd query depends on the current user referred in the session

ALTER SESSION SET CURRENT_SCHEMA=TABLE_OWNER;

SELECT table_name,
         TO_NUMBER (
            EXTRACTVALUE (
               xmltype (
                  DBMS_XMLGEN.getxml ('select count(*) c from ' || table_name)),
               '/ROWSET/ROW/C'))
            COUNT
    FROM dba_tables
   WHERE owner = 'TABLE_OWNER'
ORDER BY COUNT DESC;
REM setting current_schema is required as the 2nd query depends on the current user referred in the session

ALTER SESSION SET CURRENT_SCHEMA=TABLE_OWNER;

SELECT table_name,
         TO_NUMBER (
            EXTRACTVALUE (
               xmltype (
                  DBMS_XMLGEN.getxml ('select count(*) c from ' || table_name)),
               '/ROWSET/ROW/C'))
            COUNT
    FROM dba_tables
   WHERE owner = 'TABLE_OWNER'
ORDER BY COUNT DESC;
作妖 2024-10-25 03:17:08

使用此查询将为您提供有关表所有者的实际计数

SELECT COUNT(*),tablespace_name  FROM USER_TABLES group by tablespace_name;

Use this query which will give you the actual no of counts in respect to the table owners

SELECT COUNT(*),tablespace_name  FROM USER_TABLES group by tablespace_name;
盛装女皇 2024-10-25 03:17:08
select COUNT(*) from ALL_ALL_TABLES where OWNER='<Database-name>';

……

select COUNT(*) from ALL_ALL_TABLES where OWNER='<Database-name>';

.....

故人如初 2024-10-25 03:17:08

此查询将查找特定模式中的所有对象计数

select owner, object_type, count(*) from dba_objects where owner='owner_name' group by owner, object_type order by 3 desc;

THIS QUERY WILL FIND ALL THE OBJECTS COUNTS IN A SPECIFIC SCHEMA

select owner, object_type, count(*) from dba_objects where owner='owner_name' group by owner, object_type order by 3 desc;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文