Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • VIvek Encryption Package and Its Usage Oracle
  • How to calculate PROCESSES parameter Oracle
  • Find execution plan from dba_hist_sql_plan for a specific SQL_ID and PLAN_HASH_VALUE fplan.sql Oracle
  • CPU Core related projections AWS
  • How To Transfer Passwords Between Databases (ref note: 199582.1) Oracle
  • Oracle 10g for solaris 10 Oracle
  • catall.sh Linux/Unix
  • Standby Database Behavior when a Datafile is Resized on the Primary Database Note:123883.1 Oracle
  • GSQ.sql Oracle
  • Parallel DML Oracle
  • kill all processes from specific user in solaris. Linux/Unix
  • In Addition to previous note, following grants needed on PERFSTAT user. Oracle
  • Reading parameter file and printing Linux/Unix
  • Oracle Support Metalink ID 161818.1 Oracle
  • Good Link from metalink 1 Oracle

pvm_pre_change.sql

Posted on 08-Apr-2026 By Admin

Automating Oracle Invalid Object Recompilation: A Practical Script

As Oracle DBAs, we frequently encounter situations where database objects become invalid after patches, upgrades, or schema changes. Manually recompiling these objects can be time-consuming, especially in large databases. Today I’ll share a practical script that automates the generation of recompilation commands for all invalid objects in your Oracle database.

The Problem

When objects become invalid, they need to be recompiled before they can be used. While Oracle automatically attempts to recompile objects when they’re accessed, it’s often better to proactively recompile them to avoid runtime errors and performance issues.

The Solution: pvm_pre_change.sql

This script generates a dynamic SQL file that contains all the necessary ALTER COMPILE statements for your invalid objects. Here’s how it works:

/********************************************
     Author: Paresh Mehta
     Script Name: pvm_pre_change.sql
********************************************/

column currdate new_value pvmdt noprint
select 'pvm_comp_' || to_char(SYSDATE, 'DDMONRRRR_HH24MI') || '.sql' currdate from v$instance;

spool &pvmdt

set echo off
set verify off
set lines 120 pages 2000
set head off
set time off timing off
set feedback off
prompt set pages 5000 lines 120
prompt select 'prompt '||a.owner||'.'||a.object_name||' - '||a.object_type|| chr(10)||
prompt 'alter '||
prompt decode(a.object_type,'PACKAGE BODY','PACKAGE',object_type) || ' "'||
prompt a.owner||'".'||a.object_name||' compile '||
prompt decode(a.object_type,'PACKAGE BODY','BODY;',';')
prompt from
prompt dba_objects a
prompt where   a.status = 'INVALID'
prompt and object_id not in
(
exec dbms_output.enable(NULL);
set serveroutput on size 1000000
declare
  v_objid number(10);
  total_count number(10);
  v_counter number(10) := 1;
  cursor c1 is select object_id from dba_objects where status='INVALID';
begin
  select count(1) into total_count from dba_objects where status='INVALID';
  for cur1 in c1 loop
      dbms_output.put_line(cur1.object_id);
      if v_counter < total_count then
         dbms_output.put_line(',');
      end if;
      v_counter := v_counter + 1;
  end loop;
end;
/
prompt )
prompt /

set feedback on

spool off

How to Use This Script

  1. Run the script: Execute pvm_pre_change.sql in SQL*Plus while connected as a privileged user (like SYSDBA)
  2. Review the output: The script generates a file named pvm_comp_[timestamp].sql
  3. Execute the generated script: Run the generated file to recompile all invalid objects

Key Features

  1. Dynamic filename: The output file includes a timestamp to avoid overwriting previous runs
  2. Comprehensive object handling: Handles all object types including packages, package bodies, views, etc.
  3. Proper formatting: Generates well-formatted SQL with prompts showing which object is being compiled
  4. Efficient processing: Uses PL/SQL to dynamically build the list of invalid objects

Why This Approach Works Well

  • Automation: Saves time by generating all recompilation commands at once
  • Documentation: The output file serves as a record of what was recompiled
  • Flexibility: You can review the generated script before executing it
  • Safety: The script only targets invalid objects

Best Practices

  1. Always review the generated script before executing it
  2. Run this during maintenance windows as recompilation may cause brief locks
  3. Consider running this after major database changes
  4. Monitor the recompilation process for any errors

This script has been a valuable tool in my DBA toolkit, helping to quickly resolve invalid object issues across various Oracle environments. Give it a try in your environment and let me know how it works for you!

Oracle, SQL scripts

Post navigation

Previous Post: find_encr_wallet.sql
Next Post: find_arc.sql

Related Posts

  • Standby Database File Management in 10g with STANDBY_FILE_MANAGEMENT Oracle
  • Free conference number from http://www.freeconference.com Oracle
  • Trace a SQL session from another session using ORADEBUG Oracle
  • Oracle Release Explaination Oracle
  • Sending SQLPLUS output in HTML format Oracle
  • create PLAN_TABLE command. Oracle

Categories

  • Ansible (0)
  • AWS (2)
  • Azure (1)
  • Django (0)
  • GIT (1)
  • Linux/Unix (149)
  • MYSQL (5)
  • Oracle (399)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (1)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (150)
  • SQL scripts (347)
  • SQL Server (6)
  • Uncategorized (3)
  • Videos (0)

Recent Posts

  • find_arc.sql09-Apr-2026
  • pvm_pre_change.sql08-Apr-2026
  • find_encr_wallet.sql08-Apr-2026
  • find_pdbs.sql08-Apr-2026
  • Creating a Container Database using dbaascli08-Apr-2026
  • track_autoupgrade_copy_progress.sql01-Apr-2026
  • refre.sql for multitenant01-Apr-2026
  • prepfiles.sh for step by step generating pending statistics files10-Mar-2026
  • tracksqltime.sql05-Mar-2026
  • Complete Git Tutorial for Beginners25-Dec-2025

Archives

  • 2026
  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • How to hide author name in WordPress BLOG PHP/MYSQL/Wordpress
  • ORA-1841 Error Connecting to Upgraded Database After Set PASSWORD_LIFE_TIME Oracle
  • Oracle 10g Wait Model Oracle
  • 10g RAC: Troubleshooting CRS Root.sh Problems Oracle
  • ORACLE_SID in sqlplus Oracle
  • get_ratio.sql get the ratio of users from v$session and this uses CASE-WHEN-THEN clause Oracle
  • 272332.1 CRS 10g Diagnostic Collection Guide Oracle
  • OPENING A STANDBY DATABASE IN READ-ONLY MODE Oracle

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme