The BIT_LENGTH function returns the length (bits) of a character string or bit string as an integer value. The return value of the BIT_LENGTH function may depend on the character set, because for the character string, the number of bytes taken up by a single character is different depending on the character set of the data input environment (e.g., EUC-KR: 2*8 bits). For details about character sets supported by CUBRID, see Definition and Characteristics.
BIT_LENGTH ( string )
string :
• bit string
• character string
• NULL
SELECT BIT_LENGTH('');
bit_length('')
=================
0
SELECT BIT_LENGTH('CUBRID');
bit_length('CUBRID')
=======================
48
SELECT BIT_LENGTH('큐브리드');
bit_length('큐브리드')
=========================
64
SELECT BIT_LENGTH(B'010101010');
bit_length(B'010101010')
===========================
9
CREATE TABLE bit_length_tbl (char_1 CHAR, char_2 CHAR(5), varchar_1 VARCHAR, bit_var_1 BIT VARYING);
INSERT INTO bit_length_tbl VALUES('', '', '', B''); --Length of empty string
INSERT INTO bit_length_tbl VALUES('a', 'a', 'a', B'010101010'); --English character
INSERT INTO bit_length_tbl VALUES(NULL, '큐', '큐', B'010101010'); --Korean character and NULL
INSERT INTO bit_length_tbl VALUES(' ', ' 큐', ' 큐', B'010101010'); --Korean character and space
SELECT BIT_LENGTH(char_1), BIT_LENGTH(char_2), BIT_LENGTH(varchar_1), BIT_LENGTH(bit_var_1) FROM bit_length_tbl;
bit_length(char_1) bit_length(char_2) bit_length(varchar_1) bit_length(bit_var_1)
================================================================================
8 40 0 0
8 40 8 9
NULL 40 16 9
8 40 24 9