Re: Something easy? ORA-01450: maximum key length (6398) exceeded

  • From: Tanel Põder <tanel.poder.003@xxxxxxx>
  • To: "ORACLE-L" <oracle-l@xxxxxxxxxxxxx>
  • Date: Fri, 20 Jan 2006 11:13:23 -0600

If you define CLASS VARCHAR2(2000 CHAR) then you can insert 4000 chars
irrespective of their single- or multi- bytes.

Yep, when your NLS_LENGTH_SEMANTICS is set to CHAR (or you specify it at the table column level) the behavior is same, but nevertheless the settings, there are hard limits of 2000 BYTES for CHAR and 4000 BYTES for VARCHAR2. You can't exceed those.


And beware the varchar2 case (tested on 10.2.0.1)

SQL> create table t(a varchar2(4000 char));

Table created.

SQL> insert into t values(rpad('ä',4000,'ä'));

1 row created.

SQL> select length(a) from t;

LENGTH(A)
----------
     1334


The input is silently truncated! Char case is better, it gives an error on overflow:

SQL> insert into t values(rpad('ä',2000,'ä'));
insert into t values(rpad('ä',2000,'ä'))
*
ERROR at line 1:
ORA-12899: value too large for column "SYS"."T"."A" (actual: 4000, maximum: 2000)


The index creation error was probably because the AL32UTF8 encoding was used. With AL32UTF8, Oracle has to count for max 4 bytes per character, thus couldn't allow creation of this index. If you either use UTF8 encoding (max 3 bytes per char) or just set NLS_LENGTH_SEMANTICS to BYTE before creating the tables.

Tanel.

--
//www.freelists.org/webpage/oracle-l


Other related posts: