DBA Tips Archive for Oracle


Recompiling Invalid Objects

by Jeff Hunter, Sr. Database Administrator

When applying patches or making changes to a database I often invalidate many objects with one change. As long as no changes need to be made to the object, the following SQL*Plus script will recompile any object that is invalid:

      set feedback off
      set verify off
      set echo off
      set pagesize 0
      set heading off
      spool compile.sql
      select  'alter ' ||
             decode(object_type, 'PACKAGE BODY', 'package', object_type) ||
             ' ' ||
             ' compile' ||
             decode(object_type, 'PACKAGE BODY', ' body;', ';')
      from   dba_objects
      where  status = 'INVALID'
      spool off
      set feedback on
      set verify on
      set heading on
      set pagesize 40

Copyright (c) 1998-2018 Jeffrey M. Hunter. All rights reserved.

All articles, scripts and material located at the Internet address of http://www.idevelopment.info is the copyright of Jeffrey M. Hunter and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express, prior, written permission. Application to host any of the material elsewhere can be made by contacting me at jhunter@idevelopment.info.

I have made every effort and taken great care in making sure that the material included on my web site is technically accurate, but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.

Last modified on
Saturday, 26-Aug-2000 00:00:00 EDT
Page Count: 13451