SQL LEN() Function

LEN() Function

The LEN function returns the length of the value in the text field.

SQL LEN() Syntax

SELECT LEN(column_name) FROM table_name

SQL LEN() Example

We have the following "Persons" table:

Id LastName FirstName Address City
1 Adams John Oxford Street London
2 Bush George Fifth Avenue New York
3 Carter Thomas Changan Street Beijing

Now, we want to get the length of the value in the "City" column.

We use the following SQL statement:

SELECT LEN(City) as LengthOfCity FROM Persons

The result set is similar to this:

LengthOfCity
6
8
7