BIT_LENGTH() Function in MySQL
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 :
Example-2 : BIT_LENGTH() function to find the bit-length for a number String.
SELECT BIT_LENGTH(2020) AS BitLengthOfString;
Output :
Example-3 : BIT_LENGTH() function to find the bit-length for every String in a column of a Table.
Table – Student_Details
Student_Id |
Student_Name |
1 |
Amit |
2 |
Smriti |
3 |
Virat |
4 |
Rohit |
5 |
Aishwarya |
SELECT BIT_LENGTH(Student_Name) AS BitLengthOfName
FROM Student_Details;
Output :
BitLengthOfName |
32 |
48 |
40 |
40 |
72 |
Last Updated :
21 Jun, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...