|  
  通過執(zhí)行select NUM_ROWS,table_name from user_tables where NUM_ROWS>0,是可以達(dá)到效果的。 
但是:有時候數(shù)據(jù)是不準(zhǔn)的,原因是執(zhí)行該查詢的時候要先對表進(jìn)行分析。- 
  
 
分析表的語法為:analyze table table_name compute statistics; 
如何批量對表進(jìn)行分析呢? 
1、存儲過程+游標(biāo),循環(huán),OK沒有問題,但是有點麻煩。 
create or replace procedure Pro_AnalyzeTables is 
cursor cur_tab is 
select table_name from user_tables; 
record_cur_tab cur_tab%rowtype; 
begin 
delete from DataTables; 
open cur_tab; 
loop 
fetch 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;2、Oracle中可以將結(jié)果輸出到文件,那么可以利用這個搞他一下      方法如下:      spool DataTables.sql;(這里你可以寫路徑,例如,I:\DataTable.sql,將會將數(shù)據(jù)寫入到這個文件)      select 'analyze table '||table_name||' compute statistics;' from user_tables;      spool off;      @DataTables.sql;//執(zhí)行該文件      OK,這樣對數(shù)據(jù)庫該用戶名下的所有表就分析完畢了,那么下一步就可以執(zhí)行select NUM_ROWS 
   本文出自:億恩科技【www.cmtents.com】 
      
      
		服務(wù)器租用/服務(wù)器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM] 
       |