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 | 



OCTET_LENGTH Function

Description

The OCTET_LENGTH function returns the length (byte) of a character string or bit string as an integer. Therefore, it returns 1 (byte) if the length of the bit string is 8 bits, but 2 (bytes) if the length is 9 bits.

Syntax

OCTET_LENGTH ( string )

 

string :

bit string

character string

NULL

  • string : Specifies the character or bit string whose length is to be returned in bytes. If the value is NULL, NULL is returned.
Example

--character set is euc-kr for Korean characters

 

SELECT OCTET_LENGTH('');

 octet_length('')

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

                 0

 

SELECT OCTET_LENGTH('CUBRID');

 octet_length('CUBRID')

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

                 6

 

SELECT OCTET_LENGTH('큐브리드');

 octet_length('큐브리드')

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

                 8

 

SELECT OCTET_LENGTH(B'010101010');

 octet_length(B'010101010')

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

                 2

 

CREATE TABLE octet_length_tbl (char_1 CHAR, char_2 CHAR(5), varchar_1 VARCHAR, bit_var_1 BIT VARYING);

INSERT INTO octet_length_tbl VALUES('', '', '', B''); --Length of empty string

INSERT INTO octet_length_tbl VALUES('a', 'a', 'a', B'010101010'); --English character

INSERT INTO octet_length_tbl VALUES(NULL, '큐', '큐', B'010101010'); --Korean character and NULL

INSERT INTO octet_length_tbl VALUES(' ', ' 큐', ' 큐', B'010101010'); --Korean character and space

 

SELECT OCTET_LENGTH(char_1), OCTET_LENGTH(char_2), OCTET_LENGTH(varchar_1), OCTET_LENGTH(bit_var_1) FROM octet_length_tbl;

octet_length(char_1) octet_length(char_2) octet_length(varchar_1) octet_length(bit_var_1)

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

1                      5                         0                       0

1                      5                         1                       2

NULL                   5                         2                       2

1                      5                         3                       2