BIT_LENGTH Function in SQLThe BIT_LENGTH string function of Structured Query Language returns the length of the string in bits. Syntax of BIT_LENGTH String FunctionSyntax1: This syntax uses the BIT_LENGTH function with the column name of the SQL table: In the syntax, we have to specify the name of that column on which we want to perform the BIT_LENGTH string function for finding the length of the string in bits. Syntax2: This syntax uses the BIT_LENGTH function with the string: Examples of BIT_LENGTH String functionExample 1: The following SELECT query shows the length of the word in bits: Output:
Example 2: The following SELECT query shows the length of the given string in bits: Output:
Example 3: The following SELECT query shows the length of the given sentence in bits: Output:
Example 4: The following SELECT query shows the length of the given space in bits: Output:
Example 5: The following SELECT query shows the length of the NULL word in bits: Output:
Example 6: This example uses the BIT_LENGTH function with the table in Structured Query Language. Here, we are going to create a new SQL table on which we want to execute the BIT_LENGTH function. The below CREATE TABLE statement is the syntax for creating the new SQL table in the database: The following CREATE statement creates the Employee_Grade table: The below INSERT queries insert the records of Employees with Grades and Remarks in the Employee_Grade table: The following SELECT statement displays the inserted records of the above Employee_Grade table:
Query 1: The following SELECT query uses the BIT_LENGTH function with the First_Name column of the above Employee_Grade table: This statement shows the length of the first name of each employee in bits.
Query 2: The following SELECT query uses the BIT_LENGTH function with the Last_Name column of the above Employee_Grade table: This statement shows the length of the last name of each employee in bits. Output:
Query 3: The following SELECT query uses the BIT_LENGTH function with the First_City and New_City columns of the above Employee_Grade table: This SQL statement shows the length of the first and new city of each employee in bits. Output:
Next TopicCONCAT_WS Function in SQL |