ORA-00955 Name Is Already Used by an Existing Object
ORA-00955: Name Is Already Used by an Existing Object
Section titled “ORA-00955: Name Is Already Used by an Existing Object”Error Overview
Section titled “Error Overview”Error Text: ORA-00955: name is already used by an existing object
The ORA-00955 error occurs when attempting to create a database object (table, view, index, sequence, synonym, etc.) using a name that already exists in the same schema or namespace. Oracle requires unique names for objects within the same namespace.
Common Causes
Section titled “Common Causes”1. Duplicate Object Creation
Section titled “1. Duplicate Object Creation”- Running CREATE statements multiple times
- Re-executing deployment scripts without DROP statements
- Conflicting object names from different developers
2. Schema Migration Issues
Section titled “2. Schema Migration Issues”- Importing data without proper cleanup
- Partial rollback of schema changes
- Testing scripts in production schemas
3. Namespace Confusion
Section titled “3. Namespace Confusion”- Not understanding Oracle’s namespace rules
- Forgetting about existing synonyms or views
- Case sensitivity misunderstandings
4. Application Deployment Errors
Section titled “4. Application Deployment Errors”- Missing IF NOT EXISTS logic (not natively supported in Oracle)
- Incorrect deployment order
- Failed previous deployments leaving orphaned objects
Diagnostic Queries
Section titled “Diagnostic Queries”Find Existing Object with Same Name
Section titled “Find Existing Object with Same Name”-- Search for object by nameSELECT owner, object_name, object_type, status, createdFROM dba_objectsWHERE object_name = UPPER('&object_name')ORDER BY owner, object_type;
-- Search in current schemaSELECT object_name, object_type, status, created, last_ddl_timeFROM user_objectsWHERE object_name = UPPER('&object_name');Check All Namespaces
Section titled “Check All Namespaces”-- Objects share namespaces: tables, views, sequences,-- private synonyms, stand-alone procedures, functions, packagesSELECT object_type, object_name, status, createdFROM user_objectsWHERE object_name = UPPER('&object_name')UNION ALLSELECT 'PUBLIC SYNONYM' as object_type, synonym_name, 'VALID' as status, NULL as createdFROM all_synonymsWHERE synonym_name = UPPER('&object_name') AND owner = 'PUBLIC';Find Object Dependencies
Section titled “Find Object Dependencies”-- Check if object has dependenciesSELECT name, type, referenced_owner, referenced_name, referenced_typeFROM dba_dependenciesWHERE referenced_name = UPPER('&object_name')ORDER BY name;
-- Check for synonyms pointing to the objectSELECT owner, synonym_name, table_owner, table_nameFROM dba_synonymsWHERE table_name = UPPER('&object_name');Resolution Steps
Section titled “Resolution Steps”1. Identify and Review Existing Object
Section titled “1. Identify and Review Existing Object”-- Get full object informationSELECT owner, object_name, object_type, status, created, last_ddl_timeFROM dba_objectsWHERE object_name = UPPER('EMPLOYEES')ORDER BY owner, object_type;
-- For tables, check structureDESC schema_name.table_name;
-- For views, check definitionSELECT text FROM dba_viewsWHERE view_name = UPPER('VIEW_NAME');2. Drop Existing Object (If Safe)
Section titled “2. Drop Existing Object (If Safe)”-- Drop table (with cascade for dependent objects)DROP TABLE schema_name.table_name CASCADE CONSTRAINTS PURGE;
-- Drop viewDROP VIEW schema_name.view_name;
-- Drop sequenceDROP SEQUENCE schema_name.sequence_name;
-- Drop indexDROP INDEX schema_name.index_name;
-- Drop synonymDROP SYNONYM schema_name.synonym_name;DROP PUBLIC SYNONYM synonym_name; -- Requires privileges3. Rename Existing Object
Section titled “3. Rename Existing Object”-- Rename tableALTER TABLE old_table_name RENAME TO new_table_name;
-- Rename indexALTER INDEX old_index_name RENAME TO new_index_name;
-- Rename sequenceRENAME old_sequence_name TO new_sequence_name;
-- Cannot rename views - must drop and recreate4. Use CREATE OR REPLACE (Where Supported)
Section titled “4. Use CREATE OR REPLACE (Where Supported)”-- Works for views, procedures, functions, packages, triggersCREATE OR REPLACE VIEW employee_summary ASSELECT department_id, COUNT(*) as emp_countFROM employeesGROUP BY department_id;
CREATE OR REPLACE PROCEDURE process_data ASBEGIN -- procedure code NULL;END;/
CREATE OR REPLACE TRIGGER audit_triggerAFTER INSERT ON employeesFOR EACH ROWBEGIN -- trigger code NULL;END;/5. Implement Safe DDL Scripts
Section titled “5. Implement Safe DDL Scripts”-- Check before creating tableDECLARE v_count NUMBER;BEGIN SELECT COUNT(*) INTO v_count FROM user_tables WHERE table_name = 'NEW_TABLE';
IF v_count = 0 THEN EXECUTE IMMEDIATE 'CREATE TABLE new_table ( id NUMBER PRIMARY KEY, name VARCHAR2(100) )'; DBMS_OUTPUT.PUT_LINE('Table created successfully'); ELSE DBMS_OUTPUT.PUT_LINE('Table already exists - skipping'); END IF;END;/
-- Check before creating sequenceDECLARE v_count NUMBER;BEGIN SELECT COUNT(*) INTO v_count FROM user_sequences WHERE sequence_name = 'NEW_SEQ';
IF v_count = 0 THEN EXECUTE IMMEDIATE 'CREATE SEQUENCE new_seq START WITH 1'; END IF;END;/Prevention Strategies
Section titled “Prevention Strategies”1. Use Naming Conventions
Section titled “1. Use Naming Conventions”-- Prefix objects by type and application-- Tables: TBL_APP_ENTITY or APP_ENTITY-- Views: VW_APP_ENTITY-- Indexes: IDX_TABLE_COLUMNS-- Sequences: SEQ_TABLE_ID-- Triggers: TRG_TABLE_ACTION-- Packages: PKG_APP_MODULE2. Create Deployment Framework
Section titled “2. Create Deployment Framework”-- Example deployment wrapperCREATE OR REPLACE PROCEDURE deploy_object( p_object_type VARCHAR2, p_object_name VARCHAR2, p_ddl_statement VARCHAR2, p_drop_first BOOLEAN DEFAULT FALSE) AS v_count NUMBER; v_exists BOOLEAN;BEGIN -- Check if object exists SELECT COUNT(*) INTO v_count FROM user_objects WHERE object_name = UPPER(p_object_name) AND object_type = UPPER(p_object_type);
v_exists := (v_count > 0);
IF v_exists AND p_drop_first THEN EXECUTE IMMEDIATE 'DROP ' || p_object_type || ' ' || p_object_name; v_exists := FALSE; END IF;
IF NOT v_exists THEN EXECUTE IMMEDIATE p_ddl_statement; DBMS_OUTPUT.PUT_LINE('Created: ' || p_object_type || ' ' || p_object_name); ELSE DBMS_OUTPUT.PUT_LINE('Skipped (exists): ' || p_object_type || ' ' || p_object_name); END IF;END;/3. Document Object Inventory
Section titled “3. Document Object Inventory”-- Generate object inventory reportSELECT object_type, COUNT(*) as object_countFROM user_objectsGROUP BY object_typeORDER BY object_count DESC;
-- Export object list for documentationSELECT object_name || ',' || object_type || ',' || statusFROM user_objectsORDER BY object_type, object_name;Oracle Namespace Rules
Section titled “Oracle Namespace Rules”Understanding Oracle’s namespace helps prevent conflicts:
| Namespace | Objects |
|---|---|
| Schema Object | Tables, Views, Sequences, Private Synonyms, Standalone Procedures/Functions, Packages, Materialized Views, User-defined Types |
| Constraint | Constraints (must be unique within schema) |
| Index | Indexes (must be unique within schema) |
| Trigger | Triggers (must be unique within schema) |
| Cluster | Clusters |
| Database Link | Database Links |
| Dimension | Dimensions |
Related Errors
Section titled “Related Errors”- ORA-00942 - Table or view does not exist
- ORA-00972 - Identifier is too long
- ORA-01031 - Insufficient privileges
Emergency Response
Section titled “Emergency Response”Quick Object Check
Section titled “Quick Object Check”-- Fast check for object existenceSELECT 1 FROM dualWHERE EXISTS ( SELECT 1 FROM user_objects WHERE object_name = UPPER('&object_name'));
-- Find owner of conflicting objectSELECT owner, object_typeFROM dba_objectsWHERE object_name = UPPER('&object_name');Safe Script Pattern
Section titled “Safe Script Pattern”-- Use exception handling for deploymentBEGIN EXECUTE IMMEDIATE 'CREATE TABLE test_table (id NUMBER)';EXCEPTION WHEN OTHERS THEN IF SQLCODE = -955 THEN DBMS_OUTPUT.PUT_LINE('Object already exists - continuing'); ELSE RAISE; END IF;END;/