ORA-00910 Specified Length Too Long for Datatype - Resolution Guide
ORA-00910: Specified Length Too Long for Its Datatype
Section titled “ORA-00910: Specified Length Too Long for Its Datatype”Error Overview
Section titled “Error Overview”Error Text: ORA-00910: specified length too long for its datatype
This error occurs when you try to create or alter a column with a size that exceeds the maximum allowed for the datatype. It’s most commonly encountered with VARCHAR2 columns when developers exceed the 4000-byte (or 32767-byte in extended mode) limit.
Common Causes
Section titled “Common Causes”1. VARCHAR2 Column Exceeds Maximum
Section titled “1. VARCHAR2 Column Exceeds Maximum”- Standard mode: VARCHAR2 limit is 4000 bytes
- Extended mode (12c+): VARCHAR2 limit is 32767 bytes
- Attempting to create VARCHAR2(5000) in standard mode
2. RAW Datatype Limit Exceeded
Section titled “2. RAW Datatype Limit Exceeded”- RAW maximum is 2000 bytes in standard mode
- RAW maximum is 32767 bytes in extended mode
3. NVARCHAR2 Limit Exceeded
Section titled “3. NVARCHAR2 Limit Exceeded”- NVARCHAR2 maximum is 2000 characters (4000 bytes) in standard mode
- NVARCHAR2 maximum is 16383 characters in extended mode
4. CHAR/NCHAR Limits
Section titled “4. CHAR/NCHAR Limits”- CHAR maximum is 2000 bytes
- NCHAR maximum is 1000 characters
5. Migration from Other Databases
Section titled “5. Migration from Other Databases”- MySQL VARCHAR supports up to 65535 bytes
- SQL Server VARCHAR supports up to 8000 bytes
- PostgreSQL VARCHAR supports unlimited length
Diagnostic Queries
Section titled “Diagnostic Queries”Check Current MAX_STRING_SIZE Setting
Section titled “Check Current MAX_STRING_SIZE Setting”-- Check if extended datatypes are enabledSELECT name, valueFROM v$parameterWHERE name = 'max_string_size';
-- STANDARD = 4000 byte limit for VARCHAR2-- EXTENDED = 32767 byte limit for VARCHAR2Review Column Definitions
Section titled “Review Column Definitions”-- Check existing column sizes in a tableSELECT column_name, data_type, data_length, char_length, char_usedFROM dba_tab_columnsWHERE owner = 'YOUR_SCHEMA' AND table_name = 'YOUR_TABLE'ORDER BY column_id;
-- Find all VARCHAR2 columns near the limitSELECT owner, table_name, column_name, data_lengthFROM dba_tab_columnsWHERE data_type = 'VARCHAR2' AND data_length >= 3900ORDER BY data_length DESC;Check NLS Character Set (Affects Byte vs Char Semantics)
Section titled “Check NLS Character Set (Affects Byte vs Char Semantics)”-- Character set determines byte-per-character ratioSELECT parameter, valueFROM nls_database_parametersWHERE parameter IN ('NLS_CHARACTERSET', 'NLS_NCHAR_CHARACTERSET', 'NLS_LENGTH_SEMANTICS');
-- AL32UTF8: up to 4 bytes per character-- WE8MSWIN1252: 1 byte per characterDatatype Maximum Lengths Reference
Section titled “Datatype Maximum Lengths Reference”Standard Mode (MAX_STRING_SIZE = STANDARD)
Section titled “Standard Mode (MAX_STRING_SIZE = STANDARD)”| Datatype | SQL Maximum | PL/SQL Maximum |
|---|---|---|
| VARCHAR2 | 4000 bytes | 32767 bytes |
| NVARCHAR2 | 2000 chars | 32767 bytes |
| RAW | 2000 bytes | 32767 bytes |
| CHAR | 2000 bytes | 32767 bytes |
| NCHAR | 1000 chars | 32767 bytes |
Extended Mode (MAX_STRING_SIZE = EXTENDED)
Section titled “Extended Mode (MAX_STRING_SIZE = EXTENDED)”| Datatype | SQL Maximum | PL/SQL Maximum |
|---|---|---|
| VARCHAR2 | 32767 bytes | 32767 bytes |
| NVARCHAR2 | 16383 chars | 32767 bytes |
| RAW | 32767 bytes | 32767 bytes |
Resolution Steps
Section titled “Resolution Steps”Solution 1: Use CLOB Instead of VARCHAR2
Section titled “Solution 1: Use CLOB Instead of VARCHAR2”-- For data exceeding VARCHAR2 limits, use CLOBCREATE TABLE documents ( doc_id NUMBER, doc_title VARCHAR2(200), doc_body CLOB -- Up to 4GB, replaces large VARCHAR2);
-- Alter existing column to CLOBALTER TABLE documents MODIFY (doc_body CLOB);Solution 2: Enable Extended Datatypes (Oracle 12c+)
Section titled “Solution 2: Enable Extended Datatypes (Oracle 12c+)”-- WARNING: This change is IRREVERSIBLE and requires downtime-- Must be done in UPGRADE mode
-- 1. Shut down the databaseSHUTDOWN IMMEDIATE;
-- 2. Start in UPGRADE modeSTARTUP UPGRADE;
-- 3. Change the parameterALTER SYSTEM SET max_string_size = EXTENDED SCOPE=SPFILE;
-- 4. Run the required script@?/rdbms/admin/utl32k.sql
-- 5. Restart normallySHUTDOWN IMMEDIATE;STARTUP;
-- Now VARCHAR2 can be up to 32767 bytesCREATE TABLE large_strings ( description VARCHAR2(32767));Solution 3: Reduce Column Size to Fit Within Limits
Section titled “Solution 3: Reduce Column Size to Fit Within Limits”-- Use appropriate sizes instead of oversizing-- Bad: VARCHAR2(10000) in standard mode-- Good: VARCHAR2(4000) or CLOB
CREATE TABLE customers ( name VARCHAR2(200), -- Realistic name length email VARCHAR2(254), -- RFC 5321 max email length address VARCHAR2(500), -- Reasonable address length notes CLOB -- Unlimited text);Solution 4: Use BYTE vs CHAR Semantics Appropriately
Section titled “Solution 4: Use BYTE vs CHAR Semantics Appropriately”-- If using multibyte character set (AL32UTF8),-- VARCHAR2(4000 CHAR) may exceed byte limit
-- Use BYTE semantics to stay within limitsCREATE TABLE example ( col1 VARCHAR2(4000 BYTE) -- Always fits in standard mode);
-- Or explicitly limit character lengthCREATE TABLE example2 ( col1 VARCHAR2(1000 CHAR) -- Up to 4000 bytes in AL32UTF8);Prevention Strategies
Section titled “Prevention Strategies”1. Design Standards
Section titled “1. Design Standards”-- Establish column sizing standards for your team-- Common recommendations:-- Names: VARCHAR2(100-200)-- Emails: VARCHAR2(254)-- URLs: VARCHAR2(2000)-- Codes: VARCHAR2(10-50)-- Free text: CLOB-- Comments: VARCHAR2(4000) or CLOB2. Migration Validation Script
Section titled “2. Migration Validation Script”-- Before migrating from another database, check for oversized columns-- This simulates Oracle limits against source definitionsSELECT table_name, column_name, data_type, character_maximum_length, CASE WHEN data_type IN ('varchar', 'nvarchar') AND character_maximum_length > 4000 THEN 'NEEDS CLOB OR EXTENDED MODE' ELSE 'OK' END as oracle_compatibilityFROM information_schema.columns -- Source databaseWHERE character_maximum_length > 4000;3. Pre-DDL Validation
Section titled “3. Pre-DDL Validation”-- Check max_string_size before creating tables with large columnsDECLARE v_max_string VARCHAR2(20);BEGIN SELECT value INTO v_max_string FROM v$parameter WHERE name = 'max_string_size';
IF v_max_string = 'STANDARD' THEN DBMS_OUTPUT.PUT_LINE('WARNING: VARCHAR2 limited to 4000 bytes'); DBMS_OUTPUT.PUT_LINE('Use CLOB for larger columns or enable EXTENDED mode'); ELSE DBMS_OUTPUT.PUT_LINE('Extended mode: VARCHAR2 up to 32767 bytes'); END IF;END;/Multitenant (CDB/PDB) Considerations
Section titled “Multitenant (CDB/PDB) Considerations”-- In a CDB environment, max_string_size must be set at CDB level-- All PDBs inherit the setting
-- Check setting across all PDBsSELECT con_id, name, valueFROM v$system_parameterWHERE name = 'max_string_size';
-- The change affects ALL PDBs in the container-- Cannot have different settings per PDBRelated Errors
Section titled “Related Errors”- ORA-12899: Value Too Large for Column - Data exceeds column size at INSERT/UPDATE time
- ORA-01489: Result of String Concatenation Too Long - Concatenation exceeds VARCHAR2 limit
- ORA-00932: Inconsistent Datatypes - Datatype mismatch errors
- ORA-01438: Value Larger Than Specified Precision - Numeric precision exceeded