Invalid Database Objects Analysis (dobjecti.sql)
What This Script Does
Section titled “What This Script Does”This script provides Oracle database administration functionality via the dobjecti.sql script.
The Script
Section titled “The Script”rem dobjecti.sqlremset linesize 132remttitle 'Invalid Database Objects'remcol owner format a12 heading 'OWNER'col object_name format a30 heading 'OBJECT NAME'rem col object_id format 99999 heading 'ID'col object_type format a13 heading 'OBJECT TYPE'col created format a9 heading 'CREATED'col modified format a14 heading 'MODIFIED'col status format a1 heading 'S'rembreak on owner skip 1remselect owner, object_name, object_type, created, decode( last_ddl_time, to_char(created,'mm/dd hh24:mi:ss'), null, to_char(last_ddl_time,'mm/dd hh24:mi:ss')) modified, decode( status, 'VALID', null, 'INVALID', 'I', '?' ) status from sys.dba_objects where owner like upper('&owner') and object_type like upper('&type') and object_name like upper('&object') and status != 'VALID' order by owner, object_name;
What This Script Does
Section titled “What This Script Does”This focused script identifies all invalid database objects across schemas, showing their creation and modification dates. It’s essential for database health monitoring, deployment validation, and troubleshooting compilation issues. Invalid objects can indicate dependency problems, missing privileges, or failed deployments.
Key Features
Section titled “Key Features”- Invalid Objects Only: Filters specifically for objects with status != ‘VALID’
- Flexible Filtering: Filter by owner, object type, and object name patterns
- Timestamp Information: Shows when objects were created and last modified
- Organized Output: Grouped by owner for easy review
- Status Indication: Clear invalid status marking
Run the script and provide filter criteria when prompted:
@dobjecti.sql
Input Parameters:
- Owner: Schema owner name or pattern (use % for all owners)
- Type: Object type or pattern (e.g., PROCEDURE, FUNCTION, PACKAGE)
- Object: Object name or pattern (use % for all objects)
Required Privileges
Section titled “Required Privileges”SELECT on SYS.DBA_OBJECTS
Sample Output
Section titled “Sample Output” Invalid Database Objects
OWNER OBJECT NAME OBJECT TYPE CREATED MODIFIED S------------ ------------------------------ ------------- --------- -------------- -HR CALCULATE_BONUS FUNCTION 03/15 03/20 14:30 I EMPLOYEE_REPORTS PACKAGE 02/28 03/18 16:45 I EMPLOYEE_REPORTS PACKAGE BODY 02/28 03/18 16:45 I GET_DEPARTMENT_PROC PROCEDURE 03/10 03/22 11:20 I UPDATE_SALARY_HISTORY PROCEDURE 01/15 I
FINANCE BUDGET_CALCULATIONS PACKAGE 03/01 03/25 09:15 I BUDGET_CALCULATIONS PACKAGE BODY 03/01 03/25 09:15 I MONTHLY_REPORT_VIEW VIEW 02/20 03/19 13:30 I TAX_CALCULATION_FUNC FUNCTION 03/05 I
SALES COMMISSION_TRIGGER TRIGGER 03/12 03/23 10:45 I CUSTOMER_ANALYSIS_PKG PACKAGE 02/15 03/21 15:20 I SALES_REPORT_VIEW VIEW 03/08 I
Key Output Columns
Section titled “Key Output Columns”- OWNER: Schema that owns the invalid object
- OBJECT NAME: Name of the invalid object
- OBJECT TYPE: Type of object (PROCEDURE, FUNCTION, PACKAGE, etc.)
- CREATED: Date when object was first created
- MODIFIED: Date when object was last modified (blank if never modified)
- S (Status): Status indicator (I = INVALID)
Understanding Invalid Objects
Section titled “Understanding Invalid Objects”Common Object Types That Become Invalid
Section titled “Common Object Types That Become Invalid”PL/SQL Objects
Section titled “PL/SQL Objects”- PROCEDURE: Stored procedures with compilation errors
- FUNCTION: Functions with syntax or dependency issues
- PACKAGE: Package specifications with problems
- PACKAGE BODY: Package bodies with implementation errors
- TRIGGER: Database triggers with compilation failures
Database Objects
Section titled “Database Objects”- VIEW: Views with invalid underlying tables or columns
- MATERIALIZED VIEW: MVs with dependency or privilege issues
- SYNONYM: Synonyms pointing to non-existent objects
Common Causes of Invalid Objects
Section titled “Common Causes of Invalid Objects”-
Dependency Changes
- Underlying tables or columns dropped/modified
- Referenced objects becoming invalid
- Privilege changes on dependent objects
-
Compilation Errors
- Syntax errors in PL/SQL code
- Invalid SQL statements
- Missing or incorrect references
-
Schema Changes
- Table structure modifications
- Column datatype changes
- Index or constraint modifications
-
Security Issues
- Missing privileges on referenced objects
- Revoked access to dependent schemas
- Invalid definer rights
Analysis and Resolution
Section titled “Analysis and Resolution”Prioritizing Invalid Objects
Section titled “Prioritizing Invalid Objects”-
Recently Modified Objects
- Objects with recent MODIFIED dates likely need immediate attention
- May be related to recent deployments or changes
-
Core Application Objects
- Critical business logic procedures and functions
- Frequently used packages and triggers
-
Dependency Chains
- Objects that other valid objects depend on
- Starting point for cascade compilation
Resolution Strategies
Section titled “Resolution Strategies”Automatic Compilation
Section titled “Automatic Compilation”-- Compile specific objectALTER PROCEDURE hr.calculate_bonus COMPILE;ALTER PACKAGE finance.budget_calculations COMPILE;ALTER PACKAGE BODY finance.budget_calculations COMPILE;ALTER VIEW sales.sales_report_view COMPILE;
Bulk Compilation
Section titled “Bulk Compilation”-- Use utlrp.sql for system-wide recompilation@?/rdbms/admin/utlrp.sql
-- Or use DBMS_UTILITYEXEC DBMS_UTILITY.COMPILE_SCHEMA('HR');
Common Use Cases
Section titled “Common Use Cases”-
Post-Deployment Validation
- Verify all objects compiled successfully after deployment
- Identify objects that need attention after schema changes
-
Database Health Monitoring
- Regular checks for invalid objects
- Proactive identification of compilation issues
-
Upgrade Preparation
- Clean up invalid objects before database upgrades
- Ensure all objects are valid for migration
-
Troubleshooting
- Identify root cause of application errors
- Find objects affected by schema changes
-
Change Impact Analysis
- Assess impact of proposed schema changes
- Identify dependent objects that may become invalid
Advanced Analysis
Section titled “Advanced Analysis”Find Compilation Errors
Section titled “Find Compilation Errors”-- After identifying invalid objects, check errors:SELECT owner, name, type, line, position, textFROM dba_errorsWHERE owner = 'HR'AND name = 'CALCULATE_BONUS'ORDER BY line, position;
Dependency Analysis
Section titled “Dependency Analysis”-- Find what the invalid object depends on:SELECT owner, name, type, referenced_owner, referenced_name, referenced_typeFROM dba_dependenciesWHERE owner = 'HR'AND name = 'CALCULATE_BONUS';
Cascade Impact
Section titled “Cascade Impact”-- Find what depends on the invalid object:SELECT owner, name, typeFROM dba_dependenciesWHERE referenced_owner = 'HR'AND referenced_name = 'CALCULATE_BONUS';
Filter Examples
Section titled “Filter Examples”All Invalid PL/SQL Objects
Section titled “All Invalid PL/SQL Objects”Owner: %Type: PROCEDURE,FUNCTION,PACKAGE%Object: %
Invalid Objects in Specific Schema
Section titled “Invalid Objects in Specific Schema”Owner: HRType: %Object: %
Recently Modified Invalid Objects
Section titled “Recently Modified Invalid Objects”Look for objects with MODIFIED dates in recent deployment windows.
Troubleshooting
Section titled “Troubleshooting”No Results
- Good news - no invalid objects match the criteria
- All objects in the filtered scope are valid
Many Results After Deployment
- Common after schema changes or application deployments
- Prioritize by object importance and dependency order
- Consider bulk recompilation
Persistent Invalid Objects
- Check DBA_ERRORS for compilation error details
- Verify dependencies and privileges
- May require code fixes or schema adjustments
Integration with Deployment Process
Section titled “Integration with Deployment Process”Pre-Deployment Check
Section titled “Pre-Deployment Check”-- Document current invalid objects before deployment-- Compare after deployment to identify new issues
Post-Deployment Validation
Section titled “Post-Deployment Validation”-- Run dobjecti.sql after each deployment-- Ensure no new invalid objects were introduced-- Compile or fix any issues found
Related Scripts
Section titled “Related Scripts”- dobj.sql - All database objects with status
- dobjectf.sql - Objects with full timestamps
- compile_invalid.gen - Generate compilation commands
- derror.sql - Compilation error analysis