From time to time we will need to recomplie database objects. Among the many resons why objects become invalid are : upgrades, DDL changes, patches.
Although invalid objects are recompiled automatically on use, it is useful to run this script prior to operation because this will either eliminate or minimize subsequent latencies due to on-demand automatic recompilation at runtime. So in this article we will go thru some methods i normally use to recompile invalid objects.select 'alter ' || d1.object_type || ' ' || d1.owner || '.' ||
d1.object_name || ' ' || ' compile;'
FROM dba_objects d1
WHERE d1.status = 'INVALID'
and d1.owner != 'PUBLIC'
union
select 'alter ' || d2.owner || ' ' || d2.object_type || ' ' ||
d2.object_name || ' ' || ' compile;'
FROM dba_objects d2
WHERE d2.status = 'INVALID'
and d2.owner = 'PUBLIC';
SELECT 'EXEC DBMS_DDL.alter_compile(''' || object_type || ''',''' || owner ||
''',''' || object_name || ''');'
FROM dba_objects
WHERE status = 'INVALID'
and object_type not in ('VIEW', 'SYNONYM')
ORDER BY owner, object_type, object_name;
EXEC UTL_RECOMP.recomp_serial('schema name');
EXEC UTL_RECOMP.recomp_parallel(2, 'schema name');
EXEC UTL_RECOMP.recomp_serial();
EXEC UTL_RECOMP.recomp_parallel(2);