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_LENGTH, CHARACTER_LENGTH, LENGTHB, and LENGTH are used interchangeably.
The number of characters is returned as an integer. For details on character set supported by CUBRID, see Administrator Guide > Globalization > Overview.
Note In versions lower than than CUBRID 9.0, the multibyte string returns the number of bytes in the string. Therefore, the length of one character is calculated as 2- or 3-bytes according to the charset.
CHAR_LENGTH( string )
CHARACTER_LENGTH( string )
LENGTHB( string )
LENGTH( string )
string :
• character string
• NULL
--character set is UTF-8 for Korean characters
SELECT LENGTH('');
char length('')
==================
0
SELECT LENGTH('CUBRID');
char length('CUBRID')
==================
6
SELECT LENGTH('큐브리드');
char length('큐브리드')
==================
4
CREATE TABLE length_tbl (char_1 CHAR, char_2 CHAR(5), varchar_1 VARCHAR, varchar_2 VARCHAR);
INSERT INTO length_tbl VALUES('', '', '', ''); --Length of empty string
INSERT INTO length_tbl VALUES('a', 'a', 'a', 'a'); --English character
INSERT INTO length_tbl VALUES(NULL, '큐', '큐', '큐'); --Korean character and NULL
INSERT INTO length_tbl VALUES(' ', ' 큐', ' 큐', ' 큐'); --Korean character and space
SELECT LENGTH(char_1), LENGTH(char_2), LENGTH(varchar_1), LENGTH(varchar_2) FROM length_tbl;
char_length(char_1) char_length(char_2) char_length(varchar_1) char_length(varchar_2)
================================================================================
1 5 0 0
1 5 1 1
NULL 5 1 1
1 5 2 2