Oracle Tips by Burleson Consulting
I have packages and package bodies going
invalid when I make schema changes. How do I recompile invalid
The Oracle database will invalidate objects if
a dependent object is changed. If I rebuild a table, the indexes on
that table will become invalid because they use the table's rowids
and rebuilding the table changes a row's rowid. It is the same with
objects like packages, procedures and functions.
In a development
environment with lots of users working on the same objects this can
become aggravating. Just remember that someone caused the database
to invalidate the object. You can control this by controlling who
changes objects in the database, or splitting the development into
multiple schemas so that one section does not cause another's
objects to become invalid.
You can invoke the utl_recomp package to
recompile invalid objects:
Here is a script to recompile invalid PL/SQL
packages and package bodies. You may need to run it more than
once for dependencies, if you get errors from the script.
Set heading off;
set feedback off;
set echo off;
Set lines 999;
'ALTER ' || OBJECT_TYPE ||
' ' ||
OWNER || '.' || OBJECT_NAME
|| ' COMPILE;'
status = 'INVALID'
object_type in ('PACKAGE','FUNCTION','PROCEDURE')
set heading on;
set feedback on;
set echo on;