Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

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



VARCHAR(n)/CHAR VARYING(n)

Description

Variable-length character strings are represented as VARCHAR(n), where n is the maximum number of ASCII character strings. Each English character takes up one byte. 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 maximum length of 1,073,741,823.

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; for VARCHAR(n), the length of string used are stored. 

VARCHAR(n), CHARACTER, VARYING(n), and CHAR VARYING(n) are used interchangeably.

Remark
  • STRING is the same as the VARCHAR (maximum length).
  • 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.
Example 1

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 'pacesetter' as VARCHAR(12), 'pacesetter' is stored (a 10-character string).

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

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

If you specify 'p ' as VARCHAR, 'p' is stored (if n is not specified, the default value 1,073,741,823 is used, and the trailing space is not filled with whitespace characters).

Example 2

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

If you specify '큐브리드' as CHAR(10) and then use CHAR_LENGTH() function in the EUC-KR encoding, 8 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 VARCHAR(12) in the utf-8 encoding, it is processed normally.