Object Count Analysis (objcnt.sql)
What This Script Does
Section titled “What This Script Does”Provides a comprehensive count of database objects grouped by owner and object type, including tracking of invalid objects. This script filters out system schemas to focus on application and user objects.
The Script
Section titled “The Script”rem objcnt.sqlremttitle 'Object Count Analysis'remcol owner format a20col object_type format a20col object_cnt format 99999col invalid_cnt format 99999remselect owner , object_type , 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') group by owner, object_type order by owner, object_type/
-- Count all objects for all schemas (excluding system schemas)@objcnt.sql-- Enter: [press enter for all owners]-- Enter: [press enter for all types]-- Enter: [press enter for all objects]
-- Count objects for specific owner@objcnt.sql-- Enter: SCOTT (for specific schema)-- Enter: [press enter for all types]-- Enter: [press enter for all objects]
-- Count specific object types@objcnt.sql-- Enter: [press enter for all owners]-- Enter: TABLE (for tables only)-- Enter: [press enter for all objects]
-- Count specific objects@objcnt.sql-- Enter: HR (for specific schema)-- Enter: [press enter for all types]-- Enter: EMP% (for objects starting with EMP)
Parameters
Section titled “Parameters”The script prompts for:
- owner: Schema name pattern (% for all non-system schemas)
- type: Object type pattern (% for all types)
- object: Object name pattern (% for all objects)
Required Privileges
Section titled “Required Privileges”SELECT ANY DICTIONARY-- OR --SELECT on SYS.DBA_OBJECTS
Sample Output
Section titled “Sample Output” Object Count Analysis
OWNER OBJECT_TYPE OBJECT_CNT INVALID_CNT-------------------- -------------------- ---------- -----------HR INDEX 15 0HR SEQUENCE 3 0HR TABLE 7 0HR TRIGGER 2 1HR VIEW 4 0SALES FUNCTION 8 2SALES INDEX 45 0SALES PACKAGE 12 1SALES PACKAGE BODY 12 3SALES PROCEDURE 23 0SALES SEQUENCE 5 0SALES TABLE 23 0SALES TRIGGER 15 2SALES VIEW 18 1
Key Output Columns
Section titled “Key Output Columns”- OWNER: Schema/owner name
- OBJECT_TYPE: Type of database object
- OBJECT_CNT: Total count of objects
- INVALID_CNT: Number of invalid objects
Object Types Tracked
Section titled “Object Types Tracked”Table Objects
- TABLE
- INDEX
- TRIGGER
- SEQUENCE
Code Objects
- PROCEDURE
- FUNCTION
- PACKAGE
- PACKAGE BODY
View Objects
- VIEW
- MATERIALIZED VIEW
Other Objects
- TYPE
- SYNONYM
- DATABASE LINK
Filtered Schemas
Section titled “Filtered Schemas”The script excludes these system schemas:
- SYS
- SYSTEM
- WMSYS
- OUTLN
- SCOTT
- TSMSYS
- PUBLIC
Common Use Cases
Section titled “Common Use Cases”Schema Analysis
-- Analyze objects in specific application schema@objcnt.sql-- Enter: APP_SCHEMA-- Review object distribution and invalid counts
Invalid Object Detection
-- Find schemas with invalid objects@objcnt.sql-- Look for non-zero INVALID_CNT values-- Focus remediation efforts
Development Environment Comparison
-- Compare object counts between environments@objcnt.sql-- Verify deployment completeness-- Identify missing or extra objects
Capacity Planning
-- Understand object distribution across schemas@objcnt.sql-- Plan for growth and resource allocation
Code Inventory
-- Count stored procedures, functions, and packages@objcnt.sql-- Enter: [schema]-- Enter: PROCEDURE (or FUNCTION, PACKAGE)
Analysis Insights
Section titled “Analysis Insights”High Invalid Counts
- May indicate compilation issues
- Could suggest dependency problems
- Requires investigation and remediation
Object Distribution
- Shows schema complexity
- Indicates development patterns
- Helps understand application structure
Schema Comparison
- Compare development vs. production
- Verify deployment consistency
- Identify environment differences
Invalid Object Investigation
Section titled “Invalid Object Investigation”Follow-up Queries
-- Find specific invalid objectsSELECT owner, object_name, object_type, statusFROM dba_objectsWHERE status != 'VALID' AND owner = 'SCHEMA_NAME';
Compilation Commands
-- Recompile invalid objectsEXEC DBMS_UTILITY.compile_schema('SCHEMA_NAME');
Performance Impact
Section titled “Performance Impact”- Low Impact: Simple aggregation query
- Efficient Indexing: Uses object name indexes
- Filtered Results: Excludes large system schemas
Customization Options
Section titled “Customization Options”Include Different Schemas
-- Modify the exclusion listand owner not in ('SYS','SYSTEM','CUSTOM_SYSTEM_SCHEMA')
Add Status Breakdown
-- Include more status details, sum(decode(status, 'VALID', 1, 0)) valid_cnt, sum(decode(status, 'INVALID', 1, 0)) invalid_cnt
Object Name Analysis
-- Add object name patterns, count(case when object_name like 'TMP_%' then 1 end) temp_objects