LEN function [String]

Function

Takes one argument as an input of type BINARY or STRING and returns the number of characters, as defined by the database's collation sequence, of a specified string expression, excluding trailing blanks. The result may differ from the string’s byte length for multi-byte character sets.

BINARY and VARBINARY are also allowed, in which case LEN() returns the number of bytes of the input.

LEN is an alias of LENGTH function

Syntax

LENstring_expr )

Parameters

string_expr is the string expression to be evaluated.

Example

The following example returns the value 3152:

select len(Photo) from Productswhere ID = 500

Usage

This function is the equivalent of CHAR_LENGTH ( string_expression ).

Permissions

Any user can execute LEN.

Standards and compatibility

ANSI SQL – Compliance level: Transact-SQL extension

See also

Data types CHAR, NCHAR, VARCHAR, NVARCHAR.

See Chapter 3, “SQL Data Types.”

Functions “CHAR_LENGTH function [String]” and “STR_REPLACE function [String]”.

For general information about string functions, see “String functions”.