Modified Objects Tracking (dobjectd.sql)
What This Script Does
Section titled “What This Script Does”This script tracks database object modifications by:
- Filtering objects modified within a specific date range
- Distinguishing between object creation and subsequent modifications
- Supporting pattern matching for owner, object type, and object name
- Showing object status to identify invalid objects
- Organizing output by owner for easy review
- Providing precise timestamps for change tracking
Script
Section titled “Script”rem dobjectd.sqlremremset lines 1332remttitle 'Database Objects - Modified'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 a17 heading 'CREATED'col modified format a17 heading 'MODIFIED'col status format a1 heading 'S'rembreak on owner skip 1remselect owner, object_name, object_type, to_char(created, 'MM/DD/YY HH24:MI:SS') created, to_char(decode( last_ddl_time, created, to_date(null), last_ddl_time ),'MM/DD/YY 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 last_ddl_time between to_date('&ddl_start') and to_date('&ddl_end') + 1 order by owner, object_name;
SQL> @dobjectd.sqlEnter value for owner: SCOTTEnter value for type: %Enter value for object: %Enter value for ddl_start: 01-JAN-2025Enter value for ddl_end: 31-JAN-2025
Parameters
Section titled “Parameters”- owner: Object owner pattern (% for all, specific name for single owner)
- type: Object type pattern (TABLE, INDEX, PROCEDURE, etc., % for all)
- object: Object name pattern (% for all, specific pattern for filtering)
- ddl_start: Start date for modification period (DD-MON-YYYY format)
- ddl_end: End date for modification period (DD-MON-YYYY format)
Required Privileges
Section titled “Required Privileges”- SELECT on SYS.DBA_OBJECTS
Sample Output
Section titled “Sample Output”Database Objects - Modified
OWNER OBJECT NAME OBJECT TYPE CREATED MODIFIED S------------ ------------------------------ ------------- ----------------- ----------------- -SCOTT BONUS TABLE 15/MAR/25 09:15:23 CUSTOMERS TABLE 10/JAN/25 14:30:45 25/JAN/25 16:45:12 CUSTOMER_IDX INDEX 10/JAN/25 14:31:02 25/JAN/25 16:45:15 UPDATE_SALARY PROCEDURE 20/JAN/25 11:20:30 28/JAN/25 09:10:45
HR EMPLOYEES TABLE 05/JAN/25 08:00:00 15/JAN/25 13:22:10 EMP_TRIGGER TRIGGER 05/JAN/25 08:05:30 15/JAN/25 13:22:45 PAYROLL_PKG PACKAGE 12/JAN/25 16:45:00 20/JAN/25 14:30:15 PAYROLL_PKG PACKAGE BODY 12/JAN/25 16:45:15 20/JAN/25 14:30:20 I
Key Output Columns
Section titled “Key Output Columns”- OWNER: Schema that owns the object
- OBJECT NAME: Name of the database object
- OBJECT TYPE: Type of object (TABLE, INDEX, PROCEDURE, etc.)
- CREATED: When the object was first created
- MODIFIED: When the object was last modified (blank if never modified)
- S: Status indicator (I = Invalid, blank = Valid)
Understanding the Results
Section titled “Understanding the Results”Modification vs Creation
Section titled “Modification vs Creation”- CREATED only: Object created within the date range but never modified
- CREATED + MODIFIED: Object modified after initial creation
- MODIFIED date later: Shows when changes were made
Object Status Indicators
Section titled “Object Status Indicators”- Blank: Object is valid and ready for use
- I: Object is invalid (compilation errors, dependencies broken)
- ?: Unknown status (rare)
Common Use Cases
Section titled “Common Use Cases”-
Change Management
- Track development changes
- Audit production modifications
- Document release deployments
-
Compliance Auditing
- Monitor unauthorized changes
- Track privileged operations
- Support regulatory requirements
-
Impact Analysis
- Identify recently changed objects
- Correlate changes with issues
- Plan rollback strategies
Filtering Strategies
Section titled “Filtering Strategies”Recent Changes
Section titled “Recent Changes”-- Objects modified in last 7 daysEnter value for ddl_start: 24-JAN-2025Enter value for ddl_end: 31-JAN-2025
Specific Object Types
Section titled “Specific Object Types”-- Only track table changesEnter value for type: TABLE
-- Monitor procedural code changesEnter value for type: %PROCEDURE%
Application-Specific
Section titled “Application-Specific”-- Monitor specific application schemaEnter value for owner: ORDERAPPEnter value for type: %Enter value for object: %
Change Analysis Techniques
Section titled “Change Analysis Techniques”Daily Change Summary
Section titled “Daily Change Summary”-- Summarize changes by daySELECT TO_CHAR(last_ddl_time, 'YYYY-MM-DD') change_date, object_type, COUNT(*) object_countFROM dba_objectsWHERE last_ddl_time >= TRUNC(SYSDATE) - 7GROUP BY TO_CHAR(last_ddl_time, 'YYYY-MM-DD'), object_typeORDER BY change_date DESC, object_count DESC;
Owner Activity Analysis
Section titled “Owner Activity Analysis”-- Find most active schemasSELECT owner, COUNT(*) total_changes, COUNT(DISTINCT object_type) object_types, MIN(last_ddl_time) first_change, MAX(last_ddl_time) last_changeFROM dba_objectsWHERE last_ddl_time >= SYSDATE - 30GROUP BY ownerORDER BY total_changes DESC;
Object Type Distribution
Section titled “Object Type Distribution”-- Analyze change patterns by object typeSELECT object_type, COUNT(*) change_count, COUNT(DISTINCT owner) affected_schemas, ROUND(AVG(SYSDATE - last_ddl_time), 1) avg_days_agoFROM dba_objectsWHERE last_ddl_time >= SYSDATE - 30GROUP BY object_typeORDER BY change_count DESC;
Invalid Object Analysis
Section titled “Invalid Object Analysis”Find Invalid Objects
Section titled “Find Invalid Objects”-- Focus on invalid objects from changesSELECT owner, object_name, object_type, last_ddl_time, statusFROM dba_objectsWHERE status = 'INVALID'AND last_ddl_time >= SYSDATE - 7ORDER BY last_ddl_time DESC;
Dependency Impact
Section titled “Dependency Impact”-- Find objects invalidated by changesSELECT o1.owner, o1.object_name, o1.object_type, o2.owner referenced_owner, o2.object_name referenced_object, o2.object_type referenced_typeFROM dba_dependencies d, dba_objects o1, dba_objects o2WHERE d.owner = o1.ownerAND d.name = o1.object_nameAND d.type = o1.object_typeAND d.referenced_owner = o2.ownerAND d.referenced_name = o2.object_nameAND d.referenced_type = o2.object_typeAND o1.status = 'INVALID'AND o2.last_ddl_time >= SYSDATE - 7;
Change Tracking Integration
Section titled “Change Tracking Integration”Create Change Log
Section titled “Create Change Log”-- Create table to track changesCREATE TABLE change_audit_log ( log_date DATE DEFAULT SYSDATE, owner VARCHAR2(128), object_name VARCHAR2(128), object_type VARCHAR2(23), change_type VARCHAR2(10), -- CREATE, MODIFY ddl_time DATE, status VARCHAR2(7));
-- Populate with current snapshotINSERT INTO change_audit_log (owner, object_name, object_type, change_type, ddl_time, status)SELECT owner, object_name, object_type, CASE WHEN created = last_ddl_time THEN 'CREATE' ELSE 'MODIFY' END, last_ddl_time, statusFROM dba_objectsWHERE last_ddl_time >= SYSDATE - 1;
Automated Monitoring
Section titled “Automated Monitoring”-- Find new changes since last checkSELECT o.owner, o.object_name, o.object_type, o.last_ddl_time, o.statusFROM dba_objects oWHERE o.last_ddl_time > ( SELECT NVL(MAX(ddl_time), SYSDATE - 365) FROM change_audit_log)ORDER BY o.last_ddl_time DESC;
Development Workflow Tracking
Section titled “Development Workflow Tracking”Release Deployment Verification
Section titled “Release Deployment Verification”-- Verify expected objects were deployedWITH expected_changes AS ( SELECT 'SCOTT' owner, 'CUSTOMERS' object_name, 'TABLE' object_type FROM dual UNION ALL SELECT 'SCOTT', 'UPDATE_SALARY', 'PROCEDURE' FROM dual UNION ALL SELECT 'HR', 'PAYROLL_PKG', 'PACKAGE' FROM dual)SELECT e.owner, e.object_name, e.object_type, CASE WHEN o.object_name IS NOT NULL THEN 'DEPLOYED' ELSE 'MISSING' END status, o.last_ddl_timeFROM expected_changes eLEFT JOIN dba_objects o ON e.owner = o.owner AND e.object_name = o.object_name AND e.object_type = o.object_type AND o.last_ddl_time >= DATE '2025-01-28';
Rollback Planning
Section titled “Rollback Planning”-- Identify objects for potential rollbackSELECT owner, object_name, object_type, created, last_ddl_time, CASE WHEN created = last_ddl_time THEN 'NEW OBJECT - DROP' ELSE 'MODIFIED OBJECT - RESTORE' END rollback_actionFROM dba_objectsWHERE last_ddl_time BETWEEN DATE '2025-01-28' AND DATE '2025-01-29'ORDER BY rollback_action, owner, object_name;
Security and Compliance
Section titled “Security and Compliance”Privileged User Activity
Section titled “Privileged User Activity”-- Track changes by privileged usersSELECT o.owner, COUNT(*) change_count, LISTAGG(DISTINCT o.object_type, ', ') object_typesFROM dba_objects oWHERE o.last_ddl_time >= SYSDATE - 30AND o.owner IN ('SYS', 'SYSTEM', 'SYSMAN', 'DBSNMP')GROUP BY o.ownerORDER BY change_count DESC;
Off-Hours Changes
Section titled “Off-Hours Changes”-- Identify changes made outside business hoursSELECT owner, object_name, object_type, TO_CHAR(last_ddl_time, 'DY HH24:MI:SS') change_time, last_ddl_timeFROM dba_objectsWHERE last_ddl_time >= SYSDATE - 7AND (TO_NUMBER(TO_CHAR(last_ddl_time, 'HH24')) < 8 OR TO_NUMBER(TO_CHAR(last_ddl_time, 'HH24')) > 18 OR TO_CHAR(last_ddl_time, 'DY') IN ('SAT', 'SUN'))ORDER BY last_ddl_time DESC;
Performance Considerations
Section titled “Performance Considerations”-
Date Range Limitations
- Use specific date ranges for better performance
- Avoid very large time spans
- Consider indexing on LAST_DDL_TIME
-
Pattern Matching
- Use specific object names when possible
- Limit owner patterns to necessary schemas
- Consider object type filtering
Best Practices
Section titled “Best Practices”-
Regular Monitoring
- Run daily reports for recent changes
- Establish baseline change patterns
- Alert on unexpected modifications
-
Change Documentation
- Correlate changes with change tickets
- Document deployment windows
- Track rollback procedures
-
Security Monitoring
- Monitor privileged schema changes
- Track off-hours modifications
- Review unexpected object creations
Troubleshooting
Section titled “Troubleshooting”Missing Expected Changes
Section titled “Missing Expected Changes”- Verify date range includes deployment time
- Check if objects were created in different schema
- Confirm DDL operations completed successfully
Invalid Objects After Changes
Section titled “Invalid Objects After Changes”- Identify dependency chains
- Plan compilation order
- Check for missing privileges or objects