使用 oracle db 中的查询获取 table 名称及其行数
getting the table names and their row counts using a query in oracle db
我有一个数据库,我想获取该数据库中 table 的名称以及这些 table 中的数据行数。
select table_name from dba_tables where owner = 'owner'
returns 数据库中所有 table 的名称,但我无法获取每个 table 中的行数。
查询 num_rows 列不会实时给出行数,因为它需要所有 table 到 运行 "analyze" 命令。
有没有办法使用单个查询获取两列、table 名称和每个 table 的行数?
使用:
SELECT
table_name,
num_rows,
last_analyzed
FROM dba_tables
您可能需要更新统计信息之前:
exec dbms_stats.gather_schema_stats(ownname => 'NAME');
我有一个数据库,我想获取该数据库中 table 的名称以及这些 table 中的数据行数。
select table_name from dba_tables where owner = 'owner'
returns 数据库中所有 table 的名称,但我无法获取每个 table 中的行数。
查询 num_rows 列不会实时给出行数,因为它需要所有 table 到 运行 "analyze" 命令。
有没有办法使用单个查询获取两列、table 名称和每个 table 的行数?
使用:
SELECT
table_name,
num_rows,
last_analyzed
FROM dba_tables
您可能需要更新统计信息之前:
exec dbms_stats.gather_schema_stats(ownname => 'NAME');