ORACLE 索引批量重建

按用户批量重建索引:

按用户将此用户下面非临时表上面的索引全部重建,此过程建议在SYS用户下面执行:

 

CREATE OR REPLACE PROCEDURE BATCH_REBUILD_INDEX(USER_NAME IN VARCHAR2) IS
  S_SQL   VARCHAR2(500);
  ACCOUNT NUMBER := 0;
BEGIN

  FOR LINE2 IN (SELECT T.OWNER, T.INDEX_NAME
                  FROM ALL_INDEXES T
                 WHERE T.OWNER = UPPER(USER_NAME)
                   AND T.TABLE_TYPE = 'TABLE'
                   AND T.TEMPORARY = 'N'

                   AND T.INDEX_TYPE = 'NORMAL') LOOP
    S_SQL   := 'alter index ' || LINE2.OWNER || '.' || LINE2.INDEX_NAME ||
               ' rebuild';
    ACCOUNT := ACCOUNT + 1;
    EXECUTE IMMEDIATE S_SQL;
  END LOOP;
  DBMS_OUTPUT.PUT_LINE(ACCOUNT);
EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE(SQLERRM);
END BATCH_REBUILD_INDEX;

 

 

过程在SYS用户下面创建完成后,用下面的代码调整创建好的存储过程:

 

begin

  -- Call the procedure

  batch_rebuild_index(user_name => 'hs_user'); --输入用户名

end;

posted @ 2014-03-28 11:39  凡轩之  阅读(2048)  评论(0编辑  收藏  举报