SQL - LEN Function




SQL Tutorial - SQL LEN Function


The LEN() function is a string function. It returns the length of the value in a text field.

SQL LEN() SYNTAX


SELECT LEN(columnname)
FROM
tablename

Length Example


The Products table has the following records:

ProductID ProductName ProductPrice
Prd001 Pen 40.25
Prd002 Pen 100.75
Prd003 Eraser 10.35
Prd004 Pencil 20.45
Prd005 Book 50.65
Prd006 Gum 25.22

To find the length of the value in the 'ProductName' column from the 'Products' table, the 'Len' function can be used as shown below.

SELECT ProductName, LEN(ProductName) as ProductNameLength
FROM
Products

ProductName ProductNameLength
Pen 3
Pen 3
Eraser 6
Pencil 6
Book 4
Gum 3