標籤:style ar color os sp on bs ef tt
全域暫存資料表的統計資訊是不能被收集的,如果被收集,它的統計資訊肯定為0,會造成執行計畫不準,所以要鎖定它的統計資訊,禁止系統自動收集。
--先解鎖表的統計資訊,然後刪除表的統計資訊,最後鎖住表的統計資訊
declare
v_sqlvarchar2(500);
cursor rowList1 is
select‘begin dbms_stats.unlock_table_stats(user,‘‘‘ || table_name ||‘‘‘); end;‘
from user_tables s
where s.temporary = ‘Y‘;
cursor rowList2 is
select‘begin dbms_stats.delete_table_stats(user,‘‘‘ || table_name ||‘‘‘); end;‘
from user_tables s
where s.temporary = ‘Y‘;
cursor rowList3 is
select‘begin dbms_stats.lock_table_stats(user,‘‘‘ || table_name ||‘‘‘); end;‘
from user_tables s
where s.temporary = ‘Y‘;
begin
open rowList1;
open rowList2;
open rowList3;
loop
fetch rowList1 into v_sql;
executeimmediate v_sql;
exitwhen rowList1%notfound;
endloop;
loop
fetch rowList2 into v_sql;
executeimmediate v_sql;
exitwhen rowList2%notfound;
endloop;
loop
fetch rowList3 into v_sql;
executeimmediate v_sql;
exitwhen rowList3%notfound;
endloop;
close rowList1;
close rowList2;
close rowList3;
end;
-- STATTYPE_LOCKED=‘ALL‘意思是表的統計資訊被鎖
select s.table_name,s.STATTYPE_LOCKEDfrom user_TAB_STATISTICS s where s.STATTYPE_LOCKED=‘ALL‘;
Oracle 鎖定暫存資料表統計資訊