Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

LEN

Example

Retrieve the number of characters in a given string.

SELECT LEN(‘W3Schools.com’);

Definition and Usage

The LEN() function returns the number of characters in a string.

Note that trailing spaces at the end of the string are not counted, but leading spaces at the beginning of the string are included in the length calculation.

Tip: Also consider using the DATALENGTH() function for counting the number of bytes used to store an expression in SQL.

Syntax

LEN(string)

Parameter Values

Parameter

Description

string

Mandatory. Specifies the string for which the length is returned. If the string is NULL, the function returns NULL.

Technical Details

Works in:

SQL Server (from 2008 onward), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse

More Examples

Example

Retrieve the length of a string, including leading spaces but excluding trailing spaces.

SELECT LEN(‘ W3Schools.com ‘);

Example

Retrieve the number of characters in a string.

SELECT LEN(‘2017-08’);