SET SERVEROUTPUT ON
set feedback off
set define off

DECLARE
   cur_validate     INTEGER;
   cnt_             INTEGER;
   err_             VARCHAR2(32000);
   sql_             VARCHAR2(32000);
   obj_             VARCHAR2(19);
   n_               INTEGER;

   CURSOR get_object IS
      SELECT object_name, object_type
      FROM sys.User_Objects
      WHERE object_type IN ('VIEW', 'PACKAGE', 'PACKAGE BODY')
      AND status != 'VALID';
BEGIN
   n_ := 0;
   cur_validate := dbms_sql.open_cursor;
   FOR c_ IN get_object LOOP
      IF (c_.object_type = 'VIEW') THEN
         obj_ := c_.object_type;
      ELSE
         obj_ := 'PACKAGE';
      END IF;
      sql_ := 'ALTER ' || obj_ || ' ' || c_.object_name || ' COMPILE';
      dbms_sql.parse(cur_validate, sql_, DBMS_SQL.NATIVE);
      cnt_ := dbms_sql.execute(cur_validate);
      dbms_output.put_line('RECOMPILE: ' || sql_);
      n_ := n_ + 1;
   END LOOP;
   dbms_sql.close_cursor(cur_validate);
   IF (n_ > 0) THEN
      dbms_output.put_line('RECOMPILE done !');
   ELSE
      dbms_output.put_line('Tidak Ada Object untuk di-recompile !');
   END IF;
END;
/

SET SERVEROUTPUT OFF