Open In App

BIT_LENGTH() Function in MySQL

Last Updated : 21 Jun, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

BIT_LENGTH() function in MySQL is used to find the length of a given string in bits. The input string can be a character string or number string. Syntax :

BIT_LENGTH(str)

Parameter : Required. str : A string whose bits length to be calculated. 

Returns : It returns the length of a given string in bits. 
Example-1 : BIT_LENGTH() function to find the bit-length for a character String.

SELECT BIT_LENGTH("geeksforgeeks") AS BitLengthOfString;

Output :

BitLengthOfString
104


Example-2 : BIT_LENGTH() function to find the bit-length for a number String.

SELECT BIT_LENGTH(2020) AS BitLengthOfString;

Output :

BitLengthOfString
32


Example-3 : BIT_LENGTH() function to find the bit-length for every String in a column of a Table. 

Table - Student_Details

Student_IdStudent_Name
1Amit
2Smriti
3Virat
4Rohit
5Aishwarya
SELECT BIT_LENGTH(Student_Name) AS BitLengthOfName 
FROM Student_Details;

Output :

BitLengthOfName
32
48
40
40
72

Next Article
Article Tags :

Similar Reads