Re-compiling PL/SQL script

Sometimes when we alter tables all procedure which calling those table will be invalid. If relation is just a few number, its easy to recompile those procedure/package by hit compile button in GUI such as TOAD or SQL Detective.

But if it has many relation into procedure, package or function. Its more simpler to recompile all invalid procedure by running this command :

ALTER PROCEDURE | FUNCTION| PACKAGE [<schema>.] <name> COMPILE [BODY]

To find all invalid object we may use :
select ‘ALTER ‘ || OBJECT_TYPE || ‘ ‘ ||OWNER || ‘.’ || OBJECT_NAME || ‘ COMPILE;’
from dba_objects
where status = ‘INVALID’
and object_type in (‘PACKAGE’,’FUNCTION’,’PROCEDURE’)
and owner = [schema_name]

and then execute command by EXECUTE_IMMEDIATE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s