Recompiling dependent objects in Oracle

best practicesoracle-10g

I wonder what is the best practice to recompile Oracle 10g programmable objects that become invalid due to changes in one of them.

To be more specific, I have a few packages, that use schema level types. I also have triggers in the system that call functions/procedures from packages.
From what I understand, changes in package body don't require any further actions (except recompiling the body). However, if I change package , I have to recompile bunch of triggers that use this package and other packages that have dependencies on it.

So far I just grabbed list of invalid objects and recompiled them or used DBMS_UTILITY.compile_schema.

Thank you.

Best Answer

The trick is get the packages and dependent code recompiled in one go. If you are refreshing a development database with new data you will have an enormous list of invalid procedures. As well, with dependent code you find yourself recompiling over and over. You can use this command located in $ORACLE_HOME/rdbms/admin/utlrcmp.sql:

BEGIN
 UTL_RECOMP.RECOMP_SERIAL(schema => ‘MY_SCHEMA_NAME’);
END;

(available from 9i but improved for 10g and 11)

If you have packages that are not valid and will not be valid, for whatever reason, you can use this package from Martin Mares which will recursively compile all invalid objects except the ones you specify.

As far as best practice goes I try to limit the dependency chain. It's always a toss up between "Don't repeat yourself" which encourages dependencies and having stand alone packages.

My rule of thumb is that if the package/trigger/object interacts with another database try to reduce dependencies so if there is a issue you have less places to look for sources of the problem.