The VARCHAR2 data type stores variable-length strings. The maximum string length is 32,767 bytes. When you create a VARCHAR2 column, you must specify the maximum length for the VARCHAR2 column. Although you can store a zero-length string (''), the maximum value must be at least 1 byte. ApsaraDB for OceanBase stores each value in the column in the way as you specify. Notice
From a technical point of view, a character is a code point of the database character set.
Assume that you create a database object with a VARCHAR2 column or attribute. If you specify no explicit qualifiers in the column or attribute definition, the value of the
NLS_LENGTH_SEMANTICSparameter of the session determines the length semantics.ApsaraDB for OceanBase compares the
VARCHAR2values by using non-padded comparison semantics.When you convert data between databases that use different character sets, you must ensure that the
VARCHAR2data consists of well-formed strings.
Syntax
VARCHAR2(size [BYTE | CHAR])
Parameters
| Parameter | Description |
|---|---|
| size | The number of the stored bytes or characters. |
| BYTE | Specifies that the column length is measured in bytes. |
| CHAR | Specifies that the column length is measured in characters. |
Examples
You can specify the maximum length in characters by using the CHAR qualifier.
VARCHAR2(10 CHAR)
You can specify the maximum length in bytes by using the BYTE qualifier.
VARCHAR2(10 BYTE)