The VARCHAR data type is used to store variable-length strings. When you create a VARCHAR column, you must specify the maximum length for the VARCHAR column. Although you can store a zero-length string (''), the maximum length must be at least 1 byte. ApsaraDB for OceanBase stores each value in the column in the way as you specify. If you insert a value that exceeds the specified length, ApsaraDB for OceanBase returns an error.
In ApsaraDB for OceanBase, the VARCHAR data type is synonymous with the VARCHAR2 data type. In most cases, VARCHAR2 is used.
Syntax
VARCHAR(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. |