通过执行select num_rows,table_name from user_tables where num_rows>0,是可以达到效果的。
但是:有时候数据是不准的,原因是执行该查询的时候要先对表进行分析。
分析表的语法为:analyze table table_name compute statistics;
如何批量对表进行分析呢?
1、存储过程+游标,循环,ok没有问题,但是有点麻烦。
create or replace procedure pro_analyzetables iscursor cur_tab isselect table_name from user_tables;record_cur_tab cur_tab%rowtype;begindelete from datatables;open cur_tab;loopfetch cur_tab into record_cur_tab;exit when cur_tab%notfound;execute immediate 'analyze table '||record_cur_tab.table_name||' compute statistics';end loop;insert into datatables (select table_name,num_rows from user_tables where num_rows>0);end pro_analyzetables;
,
