The CHAR data type specifies a fixed-length string. This topic describes the syntax, parameters, and usage of the CHAR data type.
Syntax
CHAR [(size [BYTE | CHAR])]
Parameters
| Parameter | Description |
|---|---|
| size | The fixed length. |
| BYTE | The column length is specified in bytes. |
| CHAR | The column length is specified in characters. |
Considerations
The CHAR data type specifies a fixed-length string. OceanBase Database ensures that all values stored in a CHAR data type column have a length equal to the fixed length specified by size. If the value you insert is shorter than the specified length, OceanBase Database fills the remaining length with spaces. For example, when you insert a 1-byte string into a column of the CHAR(10) data type, the string is padded with 10 spaces before it is stored. If the value you insert exceeds the column length, an error is returned.
The BYTE and CHAR qualifiers override the semantics specified by the NLS_LENGTH_SEMANTICS parameter, which defaults to byte semantics. To ensure correct data conversion between databases with different character sets, the CHAR data type must be composed of well-formed strings.
The default length of a CHAR data type column is 1 byte, and the maximum allowed length is 2000 bytes.
When you create a table with a CHAR data type column, the column length is specified in bytes by default. The BYTE qualifier has the same effect as the default.
If you use 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
