Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.2.1 |  CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 



CHAR(n)

Description

A fixed-length character string is represented as CHAR(n), in which n is the number of bytes in an ASCII character string. For the English alphabet, each character takes up one byte. However, for Korean characters, note that the number of bytes taken up by each character differs depending on the character set of the data input environment (e.g. EUC-KR: 2 bytes, utf-8: 3 bytes). If n is not specified, the length is set to the default value 1.

When the length of a character string exceeds n, they are truncated. When character string which is shorter than n is stored, whitespace characters are used to fill up the trailing space.

CHAR(n) and CHARACTER(n) are used interchangeably.

Remark
  • The CHAR data type is always based on the ISO 8859-1 Latin character set.
  • n is an integer between 1 and 1,073,741,823 (1G).
  • Empty quotes (' ') are used to represent a blank string. In this case, the return value of the LENGTH function is not 0, but is the fixed length defined in CHAR(n). That is, if you enter a blank string into a column with CHAR(10), the LENGTH is 10; if you enter a blank value into a CHAR with no length specified, the LENGTH is the default value 1.
  • Space characters used as filling characters are considered to be smaller than any other characters, including special characters.
Example 1

If you specify 'pacesetter' as CHAR(12), 'pacesetter ' is stored (a 10-character string plus two whitespace characters).

If you specify 'pacesetter ' as CHAR(10), 'pacesetter' is stored (a 10-character string; two whitespace characters are truncated).

If you specify 'pacesetter' as CHAR(4), 'pace' is stored (truncated as the length of the character string is greater than 4).

If you specify 'p ' as CHAR, 'p' is stored (if n is not specified, the length is set to the default value 1).

Example 2

If you specify '큐브리드' as CHAR(10) in the EUC-KR encoding, it is processed normally.

If you specify '큐브리드' as CHAR(10) and the use the CHAR_LENGTH() function in the EUC-KR encoding, 10 is stored.

If you specify '큐브리드, as CHAR(10) in the utf-8 encoding, the last character is broken (one Korean character takes up three bytes in the utf-8 encoding so it requires two more bytes).

If you specify '큐브리드' as CHAR(12) in the utf-8 encoding, it is processed normally.