Skip to content

Find Invalid Objects (dinvalid.sql)

This script helps database administrators quickly identify invalid objects in the database. Invalid objects can cause runtime errors and should be recompiled or investigated.

rem dinvalid.sql
rem
ttitle 'Invalid Database Objects'
rem
set lines 160
set pagesize 50
rem
clear col
col owner format a20 heading 'OWNER'
col object_type format a20 heading 'OBJECT_TYPE'
col object_name format a30 heading 'OBJECT_NAME'
col object_cnt format 99999 heading 'OBJ|CNT'
col invalid_cnt format 99999 heading 'INVALID|CNT'
rem
select owner
, object_type
, object_name
-- , count(*) object_cnt
-- , sum(decode( status, 'VALID', null, 1 )) invalid_cnt
from sys.dba_objects
where owner like nvl(upper('&owner'),'%')
and object_type like nvl(upper('&type'),'%')
and object_name like nvl(upper('&object'),'%')
and owner not in ('SYS','SYSTEM','WMSYS','OUTLN','SCOTT','TSMSYS','PUBLIC')
and status <> 'VALID'
-- group by owner, object_type
order by owner, object_type
/
-- Basic usage
@dinvalid.sql
-- When prompted, enter:
-- owner: ** - Schema owner to filter (use % for all)
-- type: ** - Object type to filter (use % for all)
-- object: ** - Object name pattern to filter (use % for all)

The script prompts for:

  • &owner - ** - Schema owner to filter (use % for all)
  • &type - ** - Object type to filter (use % for all)
  • &object - ** - Object name pattern to filter (use % for all)
SELECT ANY DICTIONARY
-- OR --
SELECT ON DBA_OBJECTS
OWNER OBJECT_TYPE OBJECT_NAME
-------------------- -------------------- ------------------------------
HR PROCEDURE UPDATE_JOB_HISTORY
HR TRIGGER SECURE_EMPLOYEES
SCOTT VIEW DEPT_SUMMARY
  • OWNER - Schema that owns the object
  • OBJECT_TYPE - Type of database object (PROCEDURE, FUNCTION, VIEW, etc.)
  • OBJECT_NAME - Name of the invalid object

Find All Invalid Objects

-- Check all invalid objects across all schemas
@dinvalid.sql
-- Enter: % for all parameters

Check Specific Schema

-- Find invalid objects in HR schema
@dinvalid.sql
-- Enter: HR for owner, % for type and object