|
 |
|
Oracle: recompile
Invalid Objects
Oracle Tips by Burleson Consulting |
You Asked:
I packages and package bodies gong
invalid when I make schema changes. How do I recompile invalid
objects?
We Said:
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:
EXEC
UTL_RECOMP.recomp_serial('schema name');
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.
invalid.sql
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
|