Skip to main content

How to compile all INVALID objects in Oracle

There are five ways to recompile invalid objects in schema.

  1. DBMS_DDL
  2. DBMS_UTILITY
  3. UTL_RECOMP
  4. UTLRP.SQL
  5. Manually Recompile > Best Approach
1. DBMS_DDL
This procedure is equivalent to the following SQL statement:
ALTER PROCEDUREFUNCTIONPACKAGE [.] COMPILE [BODY]


Syntax
Exec dbms_ddl.alter_compile ( type , schema, name);


Type : Must be either PROCEDURE, FUNCTION, PACKAGE, PACKAGE BODY or TRIGGER.
Schema : Database Username
Name : Objects name

Example
SQL> exec dbms_ddl.alter_compile ('PROCEDURE','SCOTT','TEST');
PL/SQL procedure successfully completed.


2. DBMS_UTILITY
This procedure compiles all procedures, functions, packages, and triggers in the specified schema.


Syntax
Exec dbms_utility.compile_schema ( schema,compile all)

Schema : Database Username
Compile All : Object type ( procedure, function, packages,trigger)

Example
SQL> exec dbms_utility.compile_schema('SCOTT');
PL/SQL procedure successfully completed.


3. UTL_RECOMP
This script is particularly useful after a major-version upgrade that typically invalidates all PL/SQL and Java objects.


Syntax
Exec UTL_RECOMP.RECOMP_SERIAL ();

Example
SQL> Exec UTL_RECOMP.RECOMP_SERIAL ();
PL/SQL procedure successfully completed.
Note: Required SYS user to run this package.


4. UTLRP.SQL
Recompiles all existing PL/SQL modules that were previously in an INVALID state, such as packages, procedures, and types.


Syntax
Located: $ORACLE_HOME/rdbms/admin

Example
  1. Start SQL*Plus: sqlplus "/ AS SYSDBA"
  2. Run the utlrp.sql script, where Oracle_home is the Oracle home path: SQL> @Oracle_home/rdbms/admin/utlrp.sql

Note: Required SYS user to run this script.
Recommended: After upgrade or migrate database.


5. Best Approach is manually recompiling all Invalid Objects


Spool recompile.sql

Select ‘alter ‘object_type’ ’object_name’ compile;’
From user_objects
Where status <> ‘VALID’
And object_type IN (‘VIEW’,’SYNONYM’,
‘PROCEDURE’,’FUNCTION’,
‘PACKAGE’,’TRIGGER’);

Spool off
@recompile.sql


Note: VIEW,SYNONYM,PROCEDURE,PACKAGE,FUNCTION,TRIGGER


Spool pkg_body.sql

Select ‘alter package ’object_name’ compile body;’
From user_objects
where status <> ‘VALID’
And object_type = ‘PACKAGE BODY’;

Spool off
@pkg_body.sql


Spool undefined.sql

select ‘alter materizlized view ’object_name’ compile;’
From user_objects
where status <> ‘VALID’
And object_type =‘UNDEFINED’;

Spool off
@undefined.sql


Spool javaclass.sql

Select ‘alter java class ’object_name’ resolve;’
from user_objects
where status <> ‘VALID’
And object_type =‘JAVA CLASS’;

Spool off
@javaclass.sql


Spool typebody.sql

Select ‘alter type ‘object_name’ compile body;’
From user_objects
where status <> ‘VALID’
And object_type =‘TYPE BODY’;

Spool off
@typebody.sql


Spool public_synonym.sql

Select ‘alter public synonym ‘object_name’ compile;’
From user_objects
Where status <> ‘VALID’
And owner = ‘PUBLIC’
And object_type = ‘SYNONYM’;

Spool off
@public_synonym.sql


Comments

Popular posts from this blog

How to setup and use AME - Approval Management Engine

Approval Management Engine - AME For Purchase Requisition Approvals Purchase Requisitions can be routed for approval using the AME Approval Management Engine. This whitepaper describes how to setup AME for use with requisition approvals, and shows how a requisition approval list is built based on the AME setup. Approvers in the AME based approver list are assigned to the requisition based on the AME rules setup for the Purchase Requisition Approval transaction. Similar setup can be done for Requester Change Order Approval and for Internal Requisition Approval, although those are not specifically covered in this whitepaper. The screenshots provided are based on 11i.AME.B, and some of the navigation details are specific to 11i.AME.B. However, most of the details provided are applicable to 11i.AME.A and higher including R12. Assign AME Roles and Responsibilities AME responsibilities in 11i.AME.A are assigned directly to the users. However, In R12 or 11i.AME.B and higher, AME respons...

LDT Commands

1. Lookups == ============= FNDLOAD apps/apps O Y DOWNLOAD $FND_TOP/patch/115/import/aflvmlu.lct XX_CUSTOM_LKP.ldt FND_LOOKUP_TYPE APPLICATION_SHORT_NAME="XXCUST" LOOKUP_TYPE="XX_LOOKUP_TYPE" FNDLOAD apps/apps O Y UPLOAD $FND_TOP/patch/115/import/aflvmlu.lct XX_BLOG_LKP.ldt UPLOAD_MODE=REPLACE CUSTOM_MODE=FORCE 2. Concurrent Program == ============================= FNDLOAD apps/apps O Y DOWNLOAD $FND_TOP/patch/115/import/afcpprog.lct XX_BLOG_CP.ldt PROGRAM APPLICATION_SHORT_NAME="XXCUST" CONCURRENT_PROGRAM_NAME="XX_CONCURRENT_PROGRAM" FNDLOAD apps/apps 0 Y UPLOAD $FND_TOP/patch/115/import/afcpprog.lct XX_BLOG_CP.ldt = WARNING=YES UPLOAD_MODE=REPLACE CUSTOM_MODE=FORCE 3. Profile == ========= FNDLOAD apps/apps O Y DOWNLOAD $FND_TOP/patch/115/import/afscprof.lct XX_BLOG_PRF.ldt PROFILE PROFILE_NAME="XX_PROFILE_NAME" APPLICATION_SHORT_NAME="XXCUST" $FND_TOP/bin/FNDLOAD apps/apps 0 Y UPLOAD $FND_TOP/patch...