> Home > Scripts > Oracle >

Recompile invalid objects

This script should be run from SQL*plus prompt. This can also be placed in a file and ran from the SQL*plus prompt. This script can be run multiple times. Many objects in a database may depend on other objects. Therefore, this script may have to be run multiple times for all the object are valid.

 

set head off
set pagesize 0

set spool recompile_invalid_ojects.sql
SELECT 'ALTER ' || object_type ||' '|| object_name ||' COMPILE ;' FROM user_objects
WHERE status = 'INVALID'

AND OBJECT_TYPE in ('FUNCTION','VIEW', 'TRIGGER','PROCEDURE')
/
SELECT 'ALTER PACKAGE '|| object_name ||' COMPILE BODY ;' 

FROM user_objects
WHERE status = 'INVALID' 

AND OBJECT_TYPE = 'PACKAGE BODY';
/
SELECT 'ALTER PACKAGE '|| object_name ||' COMPILE PACKAGE ;' 

FROM user_objects
WHERE status = 'INVALID'

AND OBJECT_TYPE = 'PACKAGE';
/

spool off

@recompile_invalid_ojects.sql

/

exit

/