我们是重建
我的语句如下,还是想听听各位大神的建议
DECLARE
V_SQL VARCHAR2(4000);
BEGIN
FOR CUR IN (SELECT O.OBJECT_NAME
FROM USER_OBJECTS O
WHERE O.OBJECT_TYPE = 'INDEX'
AND O.LAST_DDL_TIME < SYSDATE - 30 /*一个月内没重建过的*/
AND O.TEMPORARY = 'N'
ORDER BY 1) LOOP
V_SQL := 'ALTER INDEX ' || CUR.OBJECT_NAME || ' REBUILD COMPUTE STATISTICS NOLOGGING PARALLEL';
BEGIN
EXECUTE IMMEDIATE V_SQL;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(V_SQL);
END;
V_SQL := 'ALTER INDEX ' || CUR.OBJECT_NAME || ' NOPARALLEL';
BEGIN
EXECUTE IMMEDIATE V_SQL;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(V_SQL);
END;
END LOOP;
END;