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_LENGTH/CHARACTER_LENGTH/LENGTHB/LENGTH Functions

Description

CHAR_LENGTH, LENGTHB, and LENGTH are used interchangeably.

They return the length of a character string (byte) as an integer. The return value may be different depending on the character set (e.g., EUC-KR: 2 bytes).

For details about the character sets supported by CUBRID, see Definition and Characteristics.

Syntax

CHAR_LENGTH( string )

CHARACTER_LENGTH( string )

LENGTHB( string )

LENGTH( string )

 

string :

character string

NULL

  • string: Specifies the character string whose number of characters is to be calculated. If the character string is NULL, NULL is returned.
Remark
  • The length of each space character that is included in a character string is one byte.
  • For multi-byte strings, the length of a single character is calculated as 2 or 3 bytes depending on the character set of the data input environment.
  • The length of empty quotes (") to represent a space character is 0. Note that in a CHAR(n) type, the length of a space character is n, and it is specified as 1 if n is omitted.
Example

--character set is euc-kr for Korean characters

SELECT LENGTH('');

char length('')

==================

                 0

 

SELECT LENGTH('CUBRID');

char length('CUBRID')

==================

                 6

 

SELECT LENGTH('큐브리드');

char length('큐브리드')

==================

                 8

 

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                        2             2

1                     5                        3             3