Occurs when a value is longer or out-of-range for the target column, parameter, or host variable.
DB2 SQLCODE -302 / SQLSTATE 22001 signals that a string or numeric value exceeds the size of the target column or host variable. Trim, cast, or enlarge the target data type, then re-run the statement to resolve the error.
SQLCODE -302, SQLSTATE 22001: THE VALUE OF INPUT VARIABLE OR PARAMETER NUMBER <n> IS INVALID OR TOO LARGE FOR THE TARGET COLUMN OR THE TARGET VALUE.
DB2 returns SQLCODE -302 and SQLSTATE 22001 when a value you try to insert, update, or pass to a stored procedure does not fit into the defined length or precision of the destination column or host variable.
The error halts statement execution and rolls back the offending operation, protecting data integrity but blocking application flow until corrected.
The root cause is a data-size mismatch: a string longer than VARCHAR length, a numeric larger than defined precision, or a date/time outside valid range.
Implicit casts or parameter bindings can hide the mismatch until runtime.
The error also fires when host variables in embedded SQL (COBOL, Java, C) are declared smaller than the incoming value.
First, identify the offending column or parameter from the error text or db2diag.log.
Next, either shrink the source value (TRIM, SUBSTRING, ROUND) or enlarge the target type (ALTER TABLE ALTER COLUMN).
When using host variables or JDBC PreparedStatements, adjust the data type or length in the application code to match the database definition.
Bulk loads often contain unexpected long strings; validate data length before LOAD or IMPORT. ETL processes can cast DECIMAL(18,4) into DECIMAL(10,2); revise the cast.
APIs may bind CLOB data to VARCHAR; use correct setCharacterStream methods.
Stored procedures may receive JSON longer than parameter; switch to CLOB or VARCHAR(MAX) equivalent.
Implement CHECK constraints or BEFORE INSERT triggers to truncate or reject oversize data. Enforce client-side validation and use parameterized SQL that specifies the exact JDBC/CLI type.
Monitor db2diag.log for repeated -302 events and add alerting.
Periodically review column lengths as business data grows.
SQLCODE -303 / SQLSTATE 22005 indicates incompatible data type, often seen with -302. SQLCODE -311 warns about null-terminated strings larger than target. The fixes—adjust type or value—are similar.
.
No, DB2 rejects the statement to prevent silent data loss. You must trim or cast explicitly.
The position number in the error maps to the column order in the SQL or to the host variable list. Use DESCRIBE to confirm.
No. The check is integral to DB2 data integrity. You can only change schema or clean the data.
Galaxy’s AI copilot analyzes the table metadata in real time, warns when a literal or parameter exceeds column size, and suggests ALTER statements, reducing runtime errors.