The VARCHAR2 data type stores a variable-length string. This topic describes the syntax, parameters, and considerations of the VARCHAR2 data type.
Syntax
VARCHAR2(size [BYTE | CHAR])
Parameters
| Parameter | Description |
|---|---|
| size | The length of the stored data in bytes or characters. |
| BYTE | The length of the column in bytes. The default type of VARCHAR2 is BYTE. |
| CHAR | The length of the column in characters. |
Considerations
The maximum size of the VARCHAR2 data type is 32,767 bytes. When you create a VARCHAR2 column, you must specify the maximum length for the VARCHAR2 column. Although the actual minimum string allowed for storage in a column of this type is a zero-length string (''), the maximum length must be at least 1 byte. OceanBase Database stores each character value in the VARCHAR2 column based on the specified method.
The VARCHAR2 data type supports using the CHAR qualifier to specify the maximum length in characters, such as VARCHAR2(10 CHAR). The VARCHAR2 data type also supports using the BYTE qualifier to specify the maximum length in bytes, such as VARCHAR2(10 BYTE).
Notice
- Technically speaking, characters are code points in the database character set.
- When you create a database object with a VARCHAR2 column or attribute, if you do not specify a qualifier in the definition of the column or attribute, the value of the
NLS_LENGTH_SEMANTICSparameter of the session creating the column defines the length semantics. - OceanBase Database uses nonpadded comparison semantics to compare the
VARCHAR2values. - To correctly convert data between databases that use different character sets, ensure that the
VARCHAR2data consists of correctly formatted strings.