MariaDB Tutorial MariaDB Advanced MariaDB Database Account Management MariaDB References

MariaDB BIT_LENGTH() Function



The MariaDB BIT_LENGTH() function returns the length of the specified string in bits.

Syntax

BIT_LENGTH(string)

Parameters

string Required. Specify the string to return the length for.

Return Value

Returns the length of the specified string in bits.

Example 1:

The example below shows the usage of BIT_LENGTH() function.

SELECT BIT_LENGTH('Learning SQL is FUN!');
Result: 160

SELECT BIT_LENGTH(NULL);
Result: NULL

SELECT BIT_LENGTH('');
Result: 0

SELECT BIT_LENGTH(' ');
Result: 8

SELECT BIT_LENGTH('SQL Tutorial');
Result: 96

Example 2:

Consider a database table called Employee with the following records:

EmpIDNameCityAgeSalary
1JohnLondon253000
2MarryNew York242750
3JoParis272800
4KimAmsterdam303100
5RameshNew Delhi283000
6HuangBeijing282800

The statement given below can be used to get the length of records of City column in bits.

SELECT *, BIT_LENGTH(City) AS BIT_LENGTH_Value FROM Employee;

The query will produce the following result:

EmpIDNameCityAgeBIT_LENGTH_Value
1JohnLondon2572
2MarryNew York2496
3JoParis2760
4KimAmsterdam30108
5RameshNew Delhi28108
6HuangBeijing2884

❮ MariaDB Functions