Program Compilation Errors (derror.sql)
What This Script Does
Section titled “What This Script Does”This script displays compilation errors for PL/SQL objects including procedures, functions, packages, triggers, and types. It provides detailed error information with line numbers and positions to help developers debug and fix compilation issues in database objects.
Script
Section titled “Script”rem derror.sqlremttitle 'Program Errors'remcol owner format a12 heading 'OWNER'col name format a30 heading 'NAME'col type format a12 heading 'TYPE'col sequence format 999 heading 'SEQ'col line format 99999 heading 'LINE'col position format 999 heading 'POS'col text format a80 heading 'TEXT'remselect owner, name, type, sequence, line, position, text from sys.dba_errors where owner like upper('&owner') and name like upper('&name') order by owner, name, sequence;
-- Run the script in SQL*Plus or SQLcl@derror.sql
-- When prompted, enter parameters:-- owner: Schema owner pattern (% for all)-- name: Object name pattern (% for all)
-- ExamplesEnter value for owner: % -- All schemasEnter value for name: % -- All objects
Enter value for owner: HR -- Specific schemaEnter value for name: EMP_TRIGGER -- Specific object
Parameters
Section titled “Parameters”- &owner: Schema owner pattern (use % for all schemas)
- &name: Object name pattern (use % for all objects)
Required Privileges
Section titled “Required Privileges”- SELECT on SYS.DBA_ERRORS
- Typically requires DBA role or explicit grants
Sample Output
Section titled “Sample Output”Program Errors
OWNER NAME TYPE SEQ LINE POS TEXT------------ ------------------------------ ------------ --- ----- --- ----------------HR CALCULATE_SALARY FUNCTION 1 15 5 PLS-00201: identifier 'INVALID_VAR' must be declaredHR CALCULATE_SALARY FUNCTION 2 20 10 PL/SQL: Statement ignored
SALES UPDATE_COMMISSION PROCEDURE 1 8 15 ORA-00942: table or view does not existSALES UPDATE_COMMISSION PROCEDURE 2 12 1 PL/SQL: SQL Statement ignored
HR EMPLOYEE_AUDIT_TRG TRIGGER 1 5 20 PLS-00103: Encountered the symbol ";" when expecting one of the following:HR EMPLOYEE_AUDIT_TRG TRIGGER 2 5 20 ( * & = - + < / > mod rem and or
Key Output Columns
Section titled “Key Output Columns”- OWNER: Schema owner of the object
- NAME: Name of the PL/SQL object with errors
- TYPE: Object type (PROCEDURE, FUNCTION, PACKAGE, TRIGGER, etc.)
- SEQ: Error sequence number
- LINE: Line number where error occurs
- POS: Position in line where error occurs
- TEXT: Error message description
Understanding Compilation Errors
Section titled “Understanding Compilation Errors”Common Error Types
Section titled “Common Error Types”- PLS-00201: Identifier must be declared (variable/function not found)
- ORA-00942: Table or view does not exist
- PLS-00103: Syntax error - unexpected symbol
- PLS-00320: Declaration of this type must be incomplete
- ORA-06550: Line/column syntax error
Object Types with Errors
Section titled “Object Types with Errors”- PROCEDURE: Stored procedures
- FUNCTION: Functions
- PACKAGE: Package specifications and bodies
- TRIGGER: Database triggers
- TYPE: Object types
- JAVA SOURCE: Java stored procedures
Performance Analysis
Section titled “Performance Analysis”Error Impact Assessment
Section titled “Error Impact Assessment”- Invalid objects: Cannot be executed
- Dependent objects: May cascade invalidation
- Performance impact: Recompilation overhead
- Application errors: Runtime failures
Error Pattern Analysis
Section titled “Error Pattern Analysis”-- Most common error typesSELECT SUBSTR(text, 1, 20) error_pattern, COUNT(*) error_countFROM dba_errorsGROUP BY SUBSTR(text, 1, 20)ORDER BY error_count DESC;
Common Use Cases
Section titled “Common Use Cases”Development Debugging
Section titled “Development Debugging”-- Check errors for specific schema@derror.sql-- Enter schema name and %-- Fix compilation errors systematically
Deployment Validation
Section titled “Deployment Validation”-- Check for errors after deployment@derror.sql-- Enter % for both parameters-- Verify all objects compiled successfully
Dependency Troubleshooting
Section titled “Dependency Troubleshooting”-- Find objects with dependency errors@derror.sql-- Look for ORA-00942 and similar dependency errors-- Resolve in dependency order
Troubleshooting Compilation Errors
Section titled “Troubleshooting Compilation Errors”Systematic Error Resolution
Section titled “Systematic Error Resolution”-
Check error details:
@derror.sql-- Note line numbers and error types -
View object source:
SELECT text FROM dba_sourceWHERE owner = 'HR' AND name = 'CALCULATE_SALARY'ORDER BY line; -
Fix and recompile:
ALTER FUNCTION hr.calculate_salary COMPILE;
Dependency Resolution
Section titled “Dependency Resolution”-- Check object dependenciesSELECT owner, name, type, referenced_owner, referenced_nameFROM dba_dependenciesWHERE owner = 'HR' AND name = 'CALCULATE_SALARY'ORDER BY referenced_owner, referenced_name;
-- Compile dependencies firstALTER TABLE hr.employees COMPILE;ALTER FUNCTION hr.get_department COMPILE;ALTER FUNCTION hr.calculate_salary COMPILE;
Mass Compilation
Section titled “Mass Compilation”-- Compile all invalid objectsEXEC DBMS_UTILITY.COMPILE_SCHEMA('HR');
-- Or use UTL_RECOMP for parallel compilationEXEC UTL_RECOMP.RECOMP_PARALLEL();
Advanced Analysis
Section titled “Advanced Analysis”Error Trend Analysis
Section titled “Error Trend Analysis”-- Group errors by type and objectSELECT owner, type, COUNT(DISTINCT name) objects_with_errors, COUNT(*) total_errorsFROM dba_errorsGROUP BY owner, typeORDER BY total_errors DESC;
Cross-Reference with Invalid Objects
Section titled “Cross-Reference with Invalid Objects”-- Compare with DBA_OBJECTS statusSELECT e.owner, e.name, e.type, o.status object_status, COUNT(*) error_countFROM dba_errors e, dba_objects oWHERE e.owner = o.ownerAND e.name = o.object_nameAND e.type = o.object_typeGROUP BY e.owner, e.name, e.type, o.statusORDER BY error_count DESC;
Dependency Chain Analysis
Section titled “Dependency Chain Analysis”-- Find compilation order for dependent objectsWITH dep_tree AS ( SELECT owner, name, type, referenced_owner, referenced_name, referenced_type, LEVEL compilation_level FROM dba_dependencies WHERE owner = 'HR' START WITH referenced_name IS NULL CONNECT BY PRIOR owner = referenced_owner AND PRIOR name = referenced_name AND PRIOR type = referenced_type)SELECT compilation_level, owner, name, typeFROM dep_treeWHERE (owner, name, type) IN ( SELECT owner, name, type FROM dba_errors)ORDER BY compilation_level, owner, name;
Error Resolution Strategies
Section titled “Error Resolution Strategies”Common Error Fixes
Section titled “Common Error Fixes”PLS-00201: Identifier not declared
Section titled “PLS-00201: Identifier not declared”-- Check if variable/function exists-- Add declaration or fix spellingDECLARE v_salary NUMBER; -- Add missing declarationBEGIN -- Rest of codeEND;
ORA-00942: Table does not exist
Section titled “ORA-00942: Table does not exist”-- Grant privileges on referenced tableGRANT SELECT ON hr.employees TO sales;
-- Or create synonymCREATE SYNONYM emp FOR hr.employees;
PLS-00103: Syntax error
Section titled “PLS-00103: Syntax error”-- Review syntax at specified line/position-- Common issues: missing semicolon, incorrect keywords
Automated Error Checking
Section titled “Automated Error Checking”-- Create monitoring procedureCREATE OR REPLACE PROCEDURE check_compilation_errors AS v_count NUMBER;BEGIN SELECT COUNT(*) INTO v_count FROM dba_errors;
IF v_count > 0 THEN DBMS_OUTPUT.PUT_LINE('WARNING: ' || v_count || ' compilation errors found');
FOR rec IN ( SELECT owner, name, type, COUNT(*) err_count FROM dba_errors GROUP BY owner, name, type ORDER BY err_count DESC ) LOOP DBMS_OUTPUT.PUT_LINE(rec.owner || '.' || rec.name || ' (' || rec.type || '): ' || rec.err_count || ' errors'); END LOOP; ELSE DBMS_OUTPUT.PUT_LINE('No compilation errors found'); END IF;END;/
Related Scripts
Section titled “Related Scripts”- Invalid Objects (../administration/dinvalid.sql) - Invalid object overview
- Object Dependencies (dobject.sql) - Object relationship analysis
- Source Code Analysis (dsource.sql) - PL/SQL source code examination
- Object Compilation (../generators/compile_invalid.md) - Mass compilation utilities
Best Practices
Section titled “Best Practices”Development Workflow
Section titled “Development Workflow”- Regular error checking: Run during development cycles
- Dependency awareness: Compile in correct order
- Error logging: Track and categorize common errors
- Testing: Validate fixes in development environment
Production Deployment
Section titled “Production Deployment”- Pre-deployment validation: Check for errors before release
- Post-deployment verification: Confirm successful compilation
- Rollback preparation: Have backups ready
- Monitoring: Set up alerts for new compilation errors