Other related articles:

Recently viewed articles:

SQL LENGTH Function

SQL LENGTH function returns the number of characters in string, including blanks and other special character. An error will be returned if a value for the string argument is not provided. The syntax is :

LENGTH (string)

Example 1:

The following SQL LENGTH function returns 4, which is the number of characters in input string:

SELECT LENGTH(‘john’) FROM dual;

Output:
sql-length-image1

Example 2:

The following query uses SQL LENGTH function to return employee names and length of each name from employee table for all employees who have name larger than five characters

SELECT first_name, LENGTH(first_name) FROM employee HAVING LENGTH(first_name) > 5 GROUP BY first_name;

Output:
sql-length-image2

Note: HAVING clause is used instead of WHERE clause because condition contains group function.