DECLARE
   CURSOR Invalid_Objects_Cur IS
      SELECT Object_Name, Object_Type, Last_Ddl_Time, Status
      FROM   User_Objects
      WHERE  Object_type IN ('PACKAGE','PACKAGE BODY')
        AND  Status = 'INVALID';

V_Compile_Statement VARCHAR2(500);

BEGIN
   FOR Invalid_Objects_Rec in Invalid_Objects_Cur LOOP
      V_Compile_Statement := 'ALTER PACKAGE ' || Invalid_Objects_Rec.Object_Name || ' COMPILE BODY';
      DBMS_OUTPUT.PUT_LINE(V_Compile_Statement);
      EXECUTE IMMEDIATE V_Compile_Statement;
   END LOOP;
END;
   

