The CHAR data type stores fixed-length strings. ApsaraDB for OceanBase ensures that all values stored in a CHAR column have the fixed length specified by size. If you insert a value that is shorter than the specified length, ApsaraDB for OceanBase pads the value to the specified length with spaces. If you insert a value that exceeds the specified length, ApsaraDB for OceanBase returns an error.
The BYTE and CHAR qualifiers override the semantics specified by the NLS_LENGTH_SEMANTICS parameter, which defaults to the BYTE semantics. To ensure proper data conversion between databases that use different character sets, the CHAR data must consist of well-formed strings.
Syntax
CHAR [(size [BYTE | CHAR])]
Parameters
| Parameter | Description |
|---|---|
| size | A fixed length. |
| BYTE | Specifies that the column length is measured in bytes. |
| CHAR | Specifies that the column length is measured in characters. |
The default length of a CHAR column is 1 byte. The maximum length is 2,000 bytes.
Examples
By default, when you create a table that contains a CHAR column, you specify the column length in bytes. BYTE is the default qualifier.
If you use the CHAR qualifier, you specify the column length in characters.
- Example 1
Assume that you insert a 1-byte string into the CHAR(10) column. Before the string is stored, the system pads the string to 10 bytes with spaces.
- Example 2
CHAR(10 CHAR) indicates that you specify the column length in characters.