BIT_LENGTH Function in SQL

The BIT_LENGTH string function of Structured Query Language returns the length of the string in bits.

Syntax of BIT_LENGTH String Function

Syntax1: 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 function

Example 1: The following SELECT query shows the length of the word in bits:

Output:

BIT_LENGTH_word
80

Example 2: The following SELECT query shows the length of the given string in bits:

Output:

BIT_LENGTH_string
224

Example 3: The following SELECT query shows the length of the given sentence in bits:

Output:

BIT_LENGTH_Sentence
264

Example 4: The following SELECT query shows the length of the given space in bits:

Output:

BIT_LENGTH_space
8

Example 5: The following SELECT query shows the length of the NULL word in bits:

Output:

Length
NULL

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:


Employee_IDFirst_NameLast_NameFirst_CitySecond_CityNew_CityAttendance_RemarksWork_RemarksGrade
10RameshSharmaLucknowAurangabadGhaziabad8895A2
02YaduSharmaAurangabadGhaziabadGhaziabad9582A1
07VijayRamnaNoidaGhaziabadLucknow9195A1
04BhanuRangopalrGhaziabadNoidaLucknow8582A2
11HarryRoyNoidaKanpurGhaziabad9597A1
16AkashRamnaGhaziabadMeerutAurangabad9590B1
19RamRamnaLucknowGhaziabadAurangabad8995A2

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.

First_NameBIT_LENGTH_FirstName
Ramesh48
Yadu32
Vijay40
Bhanu40
Harry40
Akash40
Ram24

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:

Last_NameBIT_LENGTH_LastName
Sharma48
Sharma48
Ramna40
Rangopalr72
Roy24
Ramna40
Ramna40

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:

First_CityBIT_LENGTH_FirstCityNew_CityBIT_LENGTH_NewCity
Lucknow56Ghaziabad72
Aurangabad80Ghaziabad72
Noida40Lucknow56
Ghaziabad72Lucknow56
Noida40Ghaziabad72
Ghaziabad72Aurangabad80
Lucknow56Aurangabad80





Latest Courses