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;

ORACLE 索引批量重建,布布扣,bubuko.com

ORACLE 索引批量重建

上一篇:开启 htaccess 配置


下一篇:委外采购单发货过账——BAPI_GOODSMVT_CREATE