ORA-00972 Identifier Is Too Long - Complete Resolution Guide
ORA-00972: Identifier Is Too Long
Section titled “ORA-00972: Identifier Is Too Long”Error Overview
Section titled “Error Overview”Error Text: ORA-00972: identifier is too long
The ORA-00972 error occurs when you attempt to create or reference a database object with a name that exceeds Oracle’s maximum identifier length. This limit varies by Oracle version.
Identifier Length Limits
Section titled “Identifier Length Limits”| Oracle Version | Maximum Length | Notes |
|---|---|---|
| Oracle 12.1 and earlier | 30 bytes | Traditional limit |
| Oracle 12.2 and later | 128 bytes | Extended identifiers enabled by default |
Important: The limit is in bytes, not characters. Multi-byte characters (UTF-8) use 2-4 bytes each.
Common Causes
Section titled “Common Causes”1. Exceeding Name Length Limit
Section titled “1. Exceeding Name Length Limit”- Table names too long
- Column names too long
- Index or constraint names too long
- PL/SQL variable names too long
2. Auto-Generated Names
Section titled “2. Auto-Generated Names”- System-generated constraint names
- Index names from ORM tools
- Hibernate/JPA generated identifiers
3. Multi-Byte Character Impact
Section titled “3. Multi-Byte Character Impact”- Using non-ASCII characters in names
- UTF-8 encoded special characters
4. Version Compatibility Issues
Section titled “4. Version Compatibility Issues”- Code written for 12.2+ running on 12.1 or earlier
- Database links to older databases
Error Examples and Solutions
Section titled “Error Examples and Solutions”Example 1: Table Name Too Long
Section titled “Example 1: Table Name Too Long”-- ERROR: Name exceeds 30 bytes (pre-12.2)CREATE TABLE employee_performance_evaluation_records_historical ( id NUMBER);-- ORA-00972: identifier is too long
-- Character count: 51 characters-- In pre-12.2: limit is 30
-- SOLUTION: Shorten the nameCREATE TABLE emp_perf_eval_records_hist ( id NUMBER);
-- Or use meaningful abbreviationsCREATE TABLE employee_perf_eval_hist ( id NUMBER);Example 2: Column Name Too Long
Section titled “Example 2: Column Name Too Long”-- ERROR: Column name too longCREATE TABLE employees ( employee_identification_number_primary NUMBER, date_of_last_performance_review DATE);-- ORA-00972: identifier is too long
-- SOLUTION: Use shorter column namesCREATE TABLE employees ( emp_id NUMBER, last_review_date DATE);
-- Add comments for documentationCOMMENT ON COLUMN employees.emp_id IS 'Employee identification number (primary key)';COMMENT ON COLUMN employees.last_review_date IS 'Date of last performance review';Example 3: Constraint Name Too Long
Section titled “Example 3: Constraint Name Too Long”-- ERROR: Constraint name too longALTER TABLE order_items ADD CONSTRAINT fk_order_items_product_catalog_product_id FOREIGN KEY (product_id) REFERENCES product_catalog(product_id);-- ORA-00972: identifier is too long
-- SOLUTION: Use shorter constraint nameALTER TABLE order_items ADD CONSTRAINT fk_oitm_prod_id FOREIGN KEY (product_id) REFERENCES product_catalog(product_id);
-- Naming convention: fk_<table_abbrev>_<column_abbrev>Example 4: Index Name Too Long
Section titled “Example 4: Index Name Too Long”-- ERROR: Index name too longCREATE INDEX idx_customer_orders_order_date_customer_id_statusON customer_orders(order_date, customer_id, status);-- ORA-00972: identifier is too long
-- SOLUTION: Shorter index nameCREATE INDEX idx_custord_dt_cust_statON customer_orders(order_date, customer_id, status);Example 5: PL/SQL Variable Too Long
Section titled “Example 5: PL/SQL Variable Too Long”-- ERROR: Variable name too longDECLARE v_employee_last_performance_review_date DATE;BEGIN NULL;END;/-- ORA-00972: identifier is too long
-- SOLUTION: Use shorter variable nameDECLARE v_last_review_date DATE; -- Or v_emp_last_perf_dtBEGIN NULL;END;/Example 6: Database Link Name Too Long
Section titled “Example 6: Database Link Name Too Long”-- ERROR: Database link name too longCREATE DATABASE LINK production_reporting_database_primary_linkCONNECT TO user IDENTIFIED BY passwordUSING 'prod_db';-- ORA-00972: identifier is too long
-- SOLUTION: Shorter link nameCREATE DATABASE LINK prod_report_primaryCONNECT TO user IDENTIFIED BY passwordUSING 'prod_db';Checking Your Oracle Version and Limit
Section titled “Checking Your Oracle Version and Limit”-- Check Oracle versionSELECT banner FROM v$version WHERE banner LIKE 'Oracle%';
-- Check maximum identifier length (12.2+)SELECT value FROM v$parameter WHERE name = 'max_string_size';
-- Check compatible parameterSHOW PARAMETER compatible;Extended Identifiers (12.2+)
Section titled “Extended Identifiers (12.2+)”Oracle 12.2 introduced 128-byte identifiers:
-- Check if extended identifiers are enabled (12.2+)SELECT value FROM v$parameter WHERE name = 'max_string_size';-- If 'EXTENDED', 128-byte identifiers are supported
-- Example: This works in 12.2+ but fails in 12.1CREATE TABLE this_is_a_very_long_table_name_that_exceeds_thirty_characters ( id NUMBER);-- Works in 12.2+, fails in 12.1 and earlierNaming Convention Best Practices
Section titled “Naming Convention Best Practices”Recommended Abbreviations
Section titled “Recommended Abbreviations”| Full Term | Abbreviation |
|---|---|
| employee | emp |
| department | dept |
| customer | cust |
| product | prod |
| order | ord |
| transaction | txn |
| number | num |
| identifier | id |
| description | desc |
| date | dt |
| amount | amt |
| status | stat |
| primary | pri |
| foreign | fk |
| index | idx |
| sequence | seq |
Naming Patterns
Section titled “Naming Patterns”-- Tables: singular noun, abbreviated if neededemployees, emp_assignments, dept_budgets
-- Primary keys: pk_<table>pk_employees, pk_emp_assignments
-- Foreign keys: fk_<child_table>_<parent_table> or fk_<child>_<column>fk_emp_dept, fk_orders_customers
-- Indexes: idx_<table>_<columns>idx_emp_name, idx_ord_date_status
-- Sequences: <table>_seq or seq_<table>employees_seq, seq_orders
-- Check constraints: chk_<table>_<rule>chk_emp_salary, chk_ord_status
-- Unique constraints: uk_<table>_<columns>uk_emp_email, uk_prod_codeCharacter Counting Helper
Section titled “Character Counting Helper”-- Check length of potential identifierSELECT LENGTH('your_potential_identifier_name') as char_length, LENGTHB('your_potential_identifier_name') as byte_lengthFROM dual;
-- For Oracle 12.1 and earlier: must be <= 30 bytes-- For Oracle 12.2 and later: can be <= 128 bytesHandling Auto-Generated Names
Section titled “Handling Auto-Generated Names”Hibernate/JPA Configuration
Section titled “Hibernate/JPA Configuration”// In persistence.xml or application.properties// Limit identifier length for older Oracle versionshibernate.physical_naming_strategy=com.example.Oracle12cNamingStrategy
// Custom naming strategy to truncate long namespublic class Oracle12cNamingStrategy implements PhysicalNamingStrategy { @Override public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) { return truncate(name, 30); }
private Identifier truncate(Identifier identifier, int maxLength) { String name = identifier.getText(); if (name.length() > maxLength) { return Identifier.toIdentifier(name.substring(0, maxLength)); } return identifier; }}Flyway/Liquibase Migrations
Section titled “Flyway/Liquibase Migrations”<!-- Liquibase: Use short names explicitly --><createTable tableName="emp_perf_hist"> <column name="id" type="NUMBER"/> <column name="emp_id" type="NUMBER"/></createTable>
<addForeignKeyConstraint constraintName="fk_eph_emp" baseTableName="emp_perf_hist" baseColumnNames="emp_id" referencedTableName="employees" referencedColumnNames="id"/>Finding Long Identifiers in Your Schema
Section titled “Finding Long Identifiers in Your Schema”-- Find tables with long namesSELECT table_name, LENGTH(table_name) as name_lengthFROM user_tablesWHERE LENGTH(table_name) > 25ORDER BY name_length DESC;
-- Find columns with long namesSELECT table_name, column_name, LENGTH(column_name) as name_lengthFROM user_tab_columnsWHERE LENGTH(column_name) > 25ORDER BY name_length DESC;
-- Find constraints with long namesSELECT table_name, constraint_name, LENGTH(constraint_name) as name_lengthFROM user_constraintsWHERE LENGTH(constraint_name) > 25ORDER BY name_length DESC;
-- Find indexes with long namesSELECT table_name, index_name, LENGTH(index_name) as name_lengthFROM user_indexesWHERE LENGTH(index_name) > 25ORDER BY name_length DESC;Renaming Existing Objects
Section titled “Renaming Existing Objects”-- Rename tableALTER TABLE old_long_table_name RENAME TO short_name;
-- Rename column (Oracle 9i+)ALTER TABLE employees RENAME COLUMN old_very_long_column_name TO short_col;
-- Rename constraintALTER TABLE employees RENAME CONSTRAINT old_constraint_name TO new_name;
-- Rename indexALTER INDEX old_index_name RENAME TO new_idx;Multi-Byte Character Considerations
Section titled “Multi-Byte Character Considerations”-- UTF-8 characters can use multiple bytes-- This might fail even if character count is under 30:SELECT LENGTHB('日本語テーブル名') as bytes FROM dual;-- Returns 24 bytes for 8 characters
-- Check database character setSELECT value FROM nls_database_parameters WHERE parameter = 'NLS_CHARACTERSET';
-- If using AL32UTF8, Asian characters use 3 bytes each-- Example: 日 = 3 bytes in UTF-8Compatibility Considerations
Section titled “Compatibility Considerations”Cross-Version Compatibility
Section titled “Cross-Version Compatibility”-- When developing for multiple Oracle versions:-- 1. Use 30-byte limit as lowest common denominator-- 2. Or check version and use appropriate limit:
DECLARE v_max_length NUMBER;BEGIN SELECT CASE WHEN version >= '12.2' THEN 128 ELSE 30 END INTO v_max_length FROM v$instance;
DBMS_OUTPUT.PUT_LINE('Max identifier length: ' || v_max_length);END;/Database Link Considerations
Section titled “Database Link Considerations”-- When accessing older databases via database link-- The remote database's limit applies
-- If local is 12.2 (128 byte) but remote is 11g (30 byte):SELECT * FROM long_table_name@old_database_link;-- May fail if table name exceeds 30 bytesQuick Reference
Section titled “Quick Reference”| Object Type | Naming Convention | Example |
|---|---|---|
| Table | noun, singular | employees |
| Column | descriptive, short | hire_date |
| Primary Key | pk_table | pk_employees |
| Foreign Key | fk_child_parent | fk_emp_dept |
| Unique | uk_table_cols | uk_emp_email |
| Check | chk_table_rule | chk_emp_salary |
| Index | idx_table_cols | idx_emp_name |
| Sequence | table_seq | employees_seq |
| Trigger | trg_table_action | trg_emp_audit |
| View | vw_name | vw_emp_details |
Related Errors
Section titled “Related Errors”- ORA-00904 - Invalid identifier
- ORA-00911 - Invalid character
- ORA-02449 - Unique/primary keys referenced by foreign keys
Summary
Section titled “Summary”- Know your Oracle version - 30 bytes (pre-12.2) vs 128 bytes (12.2+)
- Use meaningful abbreviations - Consistent naming conventions
- Count bytes, not characters - Important for multi-byte charsets
- Plan for compatibility - Use 30 bytes for cross-version support
- Configure ORM tools - Limit auto-generated name lengths
- Document full names - Use comments for long descriptive names