The CHAR data type stores fixed-length strings. This topic describes the syntax, parameters, and considerations of the CHAR data type.
Syntax
CHAR [(size [BYTE | CHAR])]
Parameters
| Parameter | Description |
|---|---|
| size | The specified fixed length. |
| BYTE | The length of the column in bytes. |
| CHAR | The length of the column in characters. |
Considerations
The CHAR data type stores fixed-length strings. The length of all values stored in the column of the CHAR data type equals the fixed length specified by size. If the inserted value is shorter than the specified length, OceanBase Database inserts blanks to pad the string to the specified length. For example, if you insert a 1-byte string into a column of the CHAR(10) type, OceanBase Database inserts blanks to pad the string to 10 bytes before it stores this string. If the inserted value exceeds this length, an error is returned.
The BYTE and CHAR qualifiers overwrite the semantics specified by the NLS_LENGTH_SEMANTICS parameter that uses BYTE as the default value. To ensure correct data conversion between databases with different character sets, you must ensure that the data of the CHAR type consists of strings in correct formats.
A column of the CHAR data type is 1-byte long by default, and the maximum length of the column is 2,000 bytes.
When you create a table and specify columns of the CHAR data type, the column length is specified in bytes by default. The value of BYTE is consistent with the default value.
If you choose the CHAR qualifier, the column length is specified in characters. For example, CHAR(10 CHAR) specifies the column length in characters.
Examples
obclient> CREATE TABLE tbl1(col1 CHAR(10), col2 INT, col3 INT);
Query OK, 0 rows affected