Oracle批量重建索引

create or replace procedure p_rebuild_all_index
   (tablespace_name 
in varchar2)
as
   sqlt 
varchar(200);
begin

    
for idx in (select index_name, tablespace_name, status from user_indexes where tablespace_name=tablespace_name and status='VALID' and temporary = 'N') loop
    
begin
           sqlt :
= 'alter index ' || idx.index_name || ' rebuild ';
           dbms_output.put_line(idx.index_name);
           dbms_output.put_line(sqlt);
           
EXECUTE IMMEDIATE sqlt;
           
--錯誤後循環繼續執行。
           EXCEPTION
           
WHEN OTHERS THEN
                dbms_output.put_line(SQLERRM);
     
end;              
     
end loop;
end;

oracle 存儲過程批量重建索引。


測試方法:

declare
    
--表空間名稱
  tablespace_name varchar2(100);
begin
  tablespace_name:
='dddd';
  p_rebuild_all_index(tablespace_name);
end;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章