LENGTH Function in SQLThe LENGTH string function of Structured Query Language returns the number of characters of the given string or word. Syntax of LENGTH String FunctionSyntax1: This syntax uses the 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 LENGTH string function for finding the number of characters of each value. Syntax2: This syntax uses the LENGTH function with the string: Examples of LENGTH String functionExample 1: The following SELECT query shows the total number of characters of the given JAVATPOINT word: Output:
Example 2: The following SELECT query shows the total number of characters of the given string: Output:
Example 3: The following SELECT query shows the length of the given sentence: Output:
Example 4: The following SELECT query shows the length of the given string: Output:
Example 5: The following SELECT query shows the length of the NULL word: Output:
Example 6: This example uses the LENGTH function with the table in Structured Query Language. In this example, we will create a new SQL table on which we want to execute the LENGTH function. The syntax for creating the new table in the SQL database is as follows: 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 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 who works in the industry.
Query 2: The following SELECT query uses the 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. Output:
Query 3: The following SELECT query uses the LENGTH function with the First_City and New_City column of the above Employee_Grade table: This SQL statement shows the length of the first and new city of each employee. Output:
Next TopicREVERSE String Function in SQL |