Recompiling invalid Oracle objects
Whenever an oracle object is marked as invalided because of a table, that has been changed, the Oracle professional can change the object to valid by using a SQL*Plus script. This script will search the Oracle data dictionary for invalid objects, create a spool file with the names of the invalid objects, than invoke a script to re-compile all of these invalid objects. The following script should be used whenever a change is made to an Oracle table or index, since the DBA must ensure that all object are valid and executable.
In Oracle8i, we now have a supported script to perform this function of re-compiling invalid objects. The utility is called Recompile PL/SQL, or RP for short. The script is called utlrp.sql and is located in the $ORACLE_HOME/rdbms/admin/ directory. However, most experienced Oracle DBAs prefer a home-made script for this purpose.
Although invalid PL/SQL modules get automatically recompiled on use, it is useful to run this script ahead of time (e.g. as one of the last steps in your migration), since this will either eliminate or minimize subsequent latencies caused due to on-demand automatic recompilation at runtime.
Oracle highly recommends running this script towards the end of of any migration/upgrade/downgrade.
Set heading off;
set feedback off;
set echo off;
Set lines 999;
Spool run_invalid.sql
select
'ALTER ' || OBJECT_TYPE || ' ' ||
OWNER || '.' || OBJECT_NAME || ' COMPILE;'
from
dba_objects
where
status = 'INVALID'
and
object_type in ('PACKAGE','FUNCTION','PROCEDURE')
;
spool off;
set heading on;
set feedback on;
set echo on;
@run_invalid.sql