VARCHAR data type

The VARCHAR data type stores character data, up to 32767 bytes.

Syntax
VARCHAR [ ( max-length [ CHAR | CHARACTER ] ) ]
Parameters
  • max-length   The maximum length of the string. If byte-length semantics are used (CHAR or CHARACTER is not specified as part of the length), then the length is in bytes, and the length must be in the range of 1 to 32767. If the length is not specified, then it is 1.

    If character-length semantics are used (CHAR or CHARACTER is specified as part of the length), then the length is in characters, and you must specify max-length. When using character-length semantics, the length multiplied by the maximum length of a character in the database encoding must not exceed 32767 bytes. The following table shows the maximum lengths for the supported types of character sets:

    Character set Maximum length of VARCHAR
    Single-byte character set 32767 characters
    Double-byte character set 16383 characters
    UTF-8 8191 characters

Remarks

Multibyte characters can be stored as VARCHAR, but the declared length refers to bytes, not characters.

VARCHAR can also be specified as CHAR VARYING or CHARACTER VARYING. Regardless of which syntax is used, the data type is described as VARCHAR.

Using character-length semantics may impact what is returned when a client application performs a DESCRIBE on a column, depending on the interface used. For example, when an embedded SQL client application performs a DESCRIBE on a column that was declared using byte-length semantics, the length returned is the byte length specified. Consequently, a VARCHAR(10) column is described as type DT_VARCHAR with a length of 10 bytes. However, when an embedded SQL client application performs a DESCRIBE on a column that was declared using character-length semantics, the length returned is the maximum byte length in the client's CHAR character set. For example, for a client that is using UTF-8 as the CHAR character set, a VARCHAR(10 CHAR) column is described as type DT_VARCHAR with a length of 40 bytes (10 characters multiplied by a maximum of four bytes per character).

See also
Standards and compatibility
  • SQL/2003   Compatible with SQL/2003. Character-length semantics is a vendor extension.