The VARCHAR2 data type stores a variable-length string. This topic describes the syntax, parameters, and usage of the VARCHAR2 data type.
Syntax
VARCHAR2(size [BYTE | CHAR])
Parameters
| Parameter | Description |
|---|---|
| size | The length of the string in bytes or characters. |
| BYTE | The length of the column in bytes. The default type for VARCHAR2 is BYTE. |
| CHAR | The length of the column in characters. |
Considerations
The maximum length of the VARCHAR2 data type is 32767. When you create a VARCHAR2 column, you must specify the maximum length. Although you can store a zero-length string (''), the maximum length must be at least 1 byte. OceanBase Database stores each character value exactly as specified in the VARCHAR2 column.
The VARCHAR2 data type can use the CHAR qualifier to specify the maximum length in characters, for example, VARCHAR2(10 CHAR). The VARCHAR2 data type can also use the BYTE qualifier to specify the maximum length in bytes, for example, VARCHAR2(10 BYTE).
Notice
- Technically, a character is a code point in the database character set.
- When you create a database object with a column or attribute that does not specify any explicit qualifiers in its definition, the length semantics are determined by the value of the
NLS_LENGTH_SEMANTICSparameter in the current session. - OceanBase Database uses unpadded comparison semantics to compare
VARCHAR2values. - When you convert data between databases with different character sets, ensure that the
VARCHAR2data consists of well-formed strings.
