ORA-01461: Can Bind a LONG Value Only for Insert into a LONG Column
ORA-01461 is one of those errors that catches developers off guard, especially when working with large string data. It occurs when Oracle's driver attempts to bind a value that exceeds the VARCHAR2 limit (4000 bytes) and internally treats it as a LONG type, but the target column is not defined as LONG. This typically surfaces in application layers — Java, Python, or .NET — rather than directly in SQL*Plus.
Top 3 Causes
1. Inserting a String Larger Than 4000 Bytes into a VARCHAR2 Column
The most common cause. When your application sends a string exceeding 4000 bytes, the JDBC or OCI driver silently promotes it to a LONG type internally, causing a conflict with the target VARCHAR2 column.
-- This will fail if :large_text exceeds 4000 bytes bound as VARCHAR2
INSERT INTO articles (id, summary)
VALUES (1, :large_text);
-- Check your column definition
SELECT column_name, data_type, data_length
FROM user_tab_columns
WHERE table_name = 'ARTICLES'
AND column_name = 'SUMMARY';
2. Wrong Column Type — VARCHAR2 Instead of CLOB
A table designed without anticipating large data volumes will have VARCHAR2 columns where CLOB should have been used. Any attempt to insert large content into such a column triggers ORA-01461.
-- Problematic table design
CREATE TABLE documents (
doc_id NUMBER PRIMARY KEY,
content VARCHAR2(4000) -- Too small for large documents!
);
-- Fix: Alter column to CLOB
ALTER TABLE documents MODIFY (content CLOB);
-- If data already exists, use a staging approach
ALTER TABLE documents ADD (content_clob CLOB);
UPDATE documents SET content_clob = content;
COMMIT;
ALTER TABLE documents DROP COLUMN content;
ALTER TABLE documents RENAME COLUMN content_clob TO content;
3. ORM Framework Mismatched Type Mapping
Frameworks like Hibernate or MyBatis automatically map Java String to Oracle VARCHAR2. When the string is large, the driver may escalate it to LONG, causing the error if the target column isn't a LOB type.
-- Target table should use CLOB
CREATE TABLE blog_posts (
post_id NUMBER PRIMARY KEY,
body CLOB
);
<!-- MyBatis: explicitly declare jdbcType -->
<insert id="insertPost">
INSERT INTO blog_posts (post_id, body)
VALUES (#{postId}, #{body, jdbcType=CLOB})
</insert>
Quick Fix Solutions
Fix 1 — Use TO_CLOB() in SQL
-- Wrap the value with TO_CLOB() for direct SQL inserts
INSERT INTO blog_posts (post_id, body)
VALUES (10, TO_CLOB('Your very long text content here...'));
-- Migrate existing VARCHAR2 data to CLOB
INSERT INTO new_table (id, body)
SELECT id, TO_CLOB(old_content)
FROM old_table;
Fix 2 — Use DBMS_LOB for PL/SQL
DECLARE
v_clob CLOB;
v_chunk VARCHAR2(4000) := 'Large text segment...';
BEGIN
DBMS_LOB.CREATETEMPORARY(v_clob, TRUE);
DBMS_LOB.WRITEAPPEND(v_clob, LENGTH(v_chunk), v_chunk);
INSERT INTO blog_posts (post_id, body) VALUES (11, v_clob);
COMMIT;
DBMS_LOB.FREETEMPORARY(v_clob);
END;
/
Fix 3 — Enable Extended VARCHAR2 (Oracle 12c+)
-- Check current setting
SHOW PARAMETER max_string_size;
-- Enable extended mode (requires restart, irreversible)
ALTER SYSTEM SET max_string_size = EXTENDED SCOPE = SPFILE;
-- Run @$ORACLE_HOME/rdbms/admin/utl32k.sql as SYSDBA after restart
-- Now you can define up to 32767 bytes
CREATE TABLE extended_test (
id NUMBER PRIMARY KEY,
content VARCHAR2(32767)
);
⚠️ Enabling EXTENDED mode is irreversible. Always test in a non-production environment first.
Prevention Tips
1. Design columns with LOB types from the start for any potentially large text fields.
During data modeling, classify columns by expected size. Anything that could exceed 4000 bytes should be defined as CLOB from day one. Include a DBA review step in your schema change process.
-- Recommended pattern
CREATE TABLE content_store (
id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
title VARCHAR2(500), -- Short: VARCHAR2 is fine
body CLOB, -- Long: always use CLOB
created DATE DEFAULT SYSDATE
);
2. Always use explicit type binding in your application layer.
Never rely on implicit type promotion by the driver. Use setClob(), setCharacterStream(), or ORM-level @Lob annotations explicitly whenever large text is involved. Add integration tests with large payloads to your CI pipeline to catch these issues before production.
Related Oracle Errors
- ORA-01460 — Unimplemented or unreasonable conversion; appears in similar type mismatch scenarios.
- ORA-00910 — Specified length too long for the data type; triggered when defining VARCHAR2 beyond allowed limits.
-
ORA-06502 — PL/SQL
VALUE_ERROR; raised when assigning oversized data to a VARCHAR2 variable. - ORA-22835 — Buffer too small for CLOB to CHAR or BLOB to RAW conversion.
📖 Want a more detailed guide?
Check out the full in-depth version (Korean) on oraerror.com — includes detailed analysis, additional SQL examples, and prevention tips.
Top comments (0)