Код:
BEGIN
FOR c IN (SELECT index_name, partition_name FROM all_ind_partitions WHERE index_owner = 'SUPERMAG' AND status='UNUSABLE')
LOOP
BEGIN
EXECUTE IMMEDIATE
'alter index supermag.' || c.index_name || ' rebuild partition ' || c.partition_name;
EXCEPTION WHEN OTHERS THEN NULL;
END;
END LOOP;
FOR c IN (SELECT index_name FROM all_indexes WHERE owner='SUPERMAG' AND status='UNUSABLE')
LOOP
BEGIN
EXECUTE IMMEDIATE
'alter index supermag.' || c.index_name || ' rebuild';
EXCEPTION WHEN OTHERS THEN NULL;
END;
END LOOP;
dbms_utility.compile_schema('SUPERMAG',FALSE);
DBMS_STATS.GATHER_SCHEMA_STATS('SUPERMAG',OPTIONS=>'gather stale');
END;