The MySQL BIT_LENGTH is one of the String Function, which is used to return the length of a specified string in bits. In this article we will show you, How to use this string BIT_LENGTH in MySQL with example.
MySQL BIT_LENGTH Syntax
The basic syntax of the BIT_LENGTH Function in MySQL is as shown below:
SELECT BIT_LENGTH (Character_Expression) FROM [Source]
In order to demonstrate this string BIT_LENGTH function in MySQL, We are going to use the customer details table data that we shown below
MySQL BIT_LENGTH Example 1
The BIT_LENGTH Function in MySQL is used to return the Bit length of a given character expression. The following query will show multiple ways to use this function by using different values.
SELECT BIT_LENGTH('A'); SELECT BIT_LENGTH('Tutorial Gateway'); -- It will return NULL as output SELECT BIT_LENGTH(NULL); SELECT BIT_LENGTH(12);
MySQL BIT_LENGTH Example 2
In this example, we are going to implement the string BIT_LENGTH function in MySQL on different columns in a customer details table.
The following statement will return the Bit length of the data present in First_Name, Last_Name, and Education Columns.
-- MySQL String BIT_LENGTH Example USE company; SELECT First_Name, BIT_LENGTH(First_Name) AS FName_Length, Last_Name, BIT_LENGTH(Last_Name) AS LName_Length, Education, BIT_LENGTH(Education) AS Edu_Length, Profession, Yearly_Income, Sales FROM customerdetails;
Thank You for Visiting Our Blog