Compile all Invalids Manually in Oracle Database
Script:
DECLARECURSOR invalid_objects_cur ISSELECT object_type, object_name, ownerFROM dba_objectsWHERE status = 'INVALID'AND object_type IN ('PACKAGE', 'PACKAGE BODY', 'PROCEDURE', 'FUNCTION', 'VIEW','TRIGGER', 'SYNONYM', 'TYPE', 'TYPE BODY', 'MATERIALIZED VIEW');BEGINFOR obj IN invalid_objects_cur LOOPBEGIN-- Compile the invalid objectIF obj.object_type = 'PACKAGE' THENEXECUTE IMMEDIATE 'ALTER PACKAGE ' || obj.owner || '.' || obj.object_name || ' COMPILE';ELSIF obj.object_type = 'PACKAGE BODY' THENEXECUTE IMMEDIATE 'ALTER PACKAGE ' || obj.owner || '.' || obj.object_name || ' COMPILE BODY';ELSIF obj.object_type = 'PROCEDURE' THENEXECUTE IMMEDIATE 'ALTER PROCEDURE ' || obj.owner || '.' || obj.object_name || ' COMPILE';ELSIF obj.object_type = 'FUNCTION' THENEXECUTE IMMEDIATE 'ALTER FUNCTION ' || obj.owner || '.' || obj.object_name || ' COMPILE';ELSIF obj.object_type = 'VIEW' THENEXECUTE IMMEDIATE 'ALTER VIEW ' || obj.owner || '.' || obj.object_name || ' COMPILE';ELSIF obj.object_type = 'TRIGGER' THENEXECUTE IMMEDIATE 'ALTER TRIGGER ' || obj.owner || '.' || obj.object_name || ' COMPILE';ELSIF obj.object_type = 'SYNONYM' THEN-- Synonyms cannot be compiled, so log a messageDBMS_OUTPUT.put_line('Synonym ' || obj.owner || '.' || obj.object_name || ' cannot be compiled, consider recreating.');ELSIF obj.object_type = 'TYPE' THENEXECUTE IMMEDIATE 'ALTER TYPE ' || obj.owner || '.' || obj.object_name || ' COMPILE';ELSIF obj.object_type = 'TYPE BODY' THENEXECUTE IMMEDIATE 'ALTER TYPE ' || obj.owner || '.' || obj.object_name || ' COMPILE BODY';ELSIF obj.object_type = 'MATERIALIZED VIEW' THENEXECUTE IMMEDIATE 'ALTER MATERIALIZED VIEW ' || obj.owner || '.' || obj.object_name || ' COMPILE';ELSEDBMS_OUTPUT.put_line('Unsupported object type: ' || obj.object_type || ' for object ' || obj.owner || '.' || obj.object_name);END IF;EXCEPTIONWHEN OTHERS THENDBMS_OUTPUT.put_line('Error compiling ' || obj.object_type || ' ' || obj.owner || '.' || obj.object_name || ': ' || SQLERRM);END;END LOOP;END;/
Post a Comment
Post a Comment