Oracle - VARCHAR2 - Characters or Bytes? What is the maximum length of VARCHAR2?

Today I came across an exception: ORA-01461, which as per Oracle is "can bind a LONG value only for insert into a LONG column".

Bytes or Characters for VARCHAR2?

To specify length, VARCHAR2 data type supports two methods:

1. In bytes: VARCHAR2(10 byte). This will support up to 10 bytes of data, which could be as few as two characters in a multibyte character set.

2. In characters: VARCHAR2(10 char). This will support to up 10 characters of data, which could be as much as 40 bytes of information.

Two issues people encounter frequently, are:
When using multibyte character sets, namely that a VARCHAR2(N) doesn't necessarily hold N characters, but rather N bytes.

The maximum length in bytes of a VARCHAR2 is 4,000.

You must specify a maximum length for a VARCHAR2 column. This maximum length must be at least 1 byte, although the actual string stored is permitted to be a zero-length string (''). You can use the CHAR qualifier, for example VARCHAR2(10 CHAR), to give the maximum length in characters instead of bytes. A character is technically a code point of the database character set. CHAR and BYTE qualifiers override the setting of the NLS_LENGTH_SEMANTICS parameter, which has a default of bytes.

For performance reasons, Oracle recommends that you use the NLS_LENGTH_SEMANTICS parameter to set length semantics and that you use the BYTE and CHAR qualifiers only when necessary to override the parameter. The maximum length of VARCHAR2 data is 4000 bytes. Oracle compares VARCHAR2 values using nonpadded comparison semantics.

Also Read Setting Maximum Open Cursors In Oracle


Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to our feed and get articles like this delivered automatically to your feed reader? Like our Facebook Page.

  1. Valuable post. I did also faced this exception but is not aware why it occurs. From your article I got to know the actual reason and how to remove it. Thanks for clearing it so nicely.
    sap project

Post a Comment
Previous Post Next Post