| ORA-01401: inserted value too large for column [message #690509] |
Fri, 04 September 2026 16:13  |
 |
Darth Waiter
Messages: 104 Registered: October 2020
|
Senior Member |
|
|
I've been using this query for a demo, since very old versions, but now that I run it in v.18 it is failing:
SQL> select vsize(cast(t."COUNTRY_NAME" as Nvarchar2(20))) from "HR"."COUNTRIES" t;
VSIZE(CAST(T."COUNTRY_NAME"ASNVARCHAR2(20)))
--------------------------------------------
18
18
14
12
12
22
10
14
14
10
12
VSIZE(CAST(T."COUNTRY_NAME"ASNVARCHAR2(20)))
--------------------------------------------
12
10
10
10
ERROR:
ORA-01401: inserted value too large for column
15 rows selected.
If I change to Varchar2, then it is working, but that defeats the purpose of the query. Since the documentation on VSIZE is, to put it mildly, lacking, I don't understand what the root cause of the above error is. What is too large for what?
|
|
|
|
|
|
|
|
| Re: ORA-01401: inserted value too large for column [message #690512 is a reply to message #690511] |
Sat, 05 September 2026 11:28  |
 |
Darth Waiter
Messages: 104 Registered: October 2020
|
Senior Member |
|
|
Ah, so Oracle does not truncate by casting, unlike MS SQL Server. It prefers to throw an erro. Gotcha!
declare @a varchar(20) = replicate('a', 20)
select @a, DATALENGTH(@a) as dl_a, cast(@a as nvarchar(10)) as cast_a, DATALENGTH(cast(@a as nvarchar(10))) as dl_cast_a
/*
dl_a cast_a dl_cast_a
-------------------- ----------- ---------- -----------
aaaaaaaaaaaaaaaaaaaa 20 aaaaaaaaaa 20
(1 row affected)
*/
|
|
|
|