Oracle数据库直接使用num_rows统计
select t.table_name,t.num_rows from sys.dba_tables t where owner = ‘test’ order by num_rows desc
当num_rows为空
可以使用analyze关键字
select ‘analyze table ’ || table_name || ’ compute statistics for table;’ from user_tables;
dm数据库由于analyze 好像不可以分析表
所以先创建一个函数
create or replace function count_rows(table_name in varchar2,owner in varchar2 default null)
return number authid current_user IS
num_rows number;
stmt varchar2(2000);
begin
if owner is null then
stmt := ‘select count() from “’ || table_name || '”’;
else
stmt := 'select count() from "’ || owner || ‘"."’ || table_name || ‘"’;
end if;
execute immediate stmt
into num_rows;
return num_rows;
end;
再查
select * from (
select t.table_name,
count_rows(table_name) num_rows
from user_tables t
) order by num_rows desc
参考:https://zhidao.baidu.com/question/1367876849102899699.html