BIT_LENGTH
Description
Returns the bit length of a string or binary value (i.e., the byte length × 8).
Syntax
BIT_LENGTH(<str>)
Parameters
<str>The string value whose bit length is to be returned.
Return Value
Returns the number of bits occupied by <str> in its binary representation, counting all 0 and 1 bits.
Examples
-
Example 1
select BIT_LENGTH("abc"), BIT_LENGTH("中国"), BIT_LENGTH(123);+-------------------+----------------------+-----------------+| BIT_LENGTH("abc") | BIT_LENGTH("中国") | BIT_LENGTH(123) |+-------------------+----------------------+-----------------+| 24 | 48 | 24 |+-------------------+----------------------+-----------------+ -
NULL argument
select BIT_LENGTH(NULL);+------------------+| BIT_LENGTH(NULL) |+------------------+| NULL |+------------------+