今天本想用
select * from user_tables t where t.NUM_ROWS>0
查询表中数据大于0的表,可结果竟然没有查出来,网上搜了一下,原来NUM_ROWS这个字段有不少问题,除了不太准确外,还有个问题就是它不是即时查询的,我刚从另外一个数据库导来的数据,自然用这个字段就查不到了。后来发现有一个语句可以解决此问题,即
analyze table table_name compute statistics;
由于需要统计的表众多,所以写了个存储过程来解决问题:
create or replace procedure statistics_all_dep
is
v_sql varchar2(1000) default '';
begin
for rs in
(
select t.TABLE_NAME from user_tables t where t.TABLE_NAME like '%DEP%'
)loop
v_sql :='analyze table '||rs.table_name||' compute statistics';
Execute immediate v_sql;
commit;
end loop;
exception
when others then
dbms_output.put_line('errm statistics_all_dep:' || sqlerrm);
end;