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.

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

LEN is an alias of LENGTH function

Syntax

LEN ( string_expr )

Parameters

string_expr is the string expression to be evaluated.

Example

Returns the characters:

select len(notes) from titles
where title_id = "PC9999"
-----------
39

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 4, “SQL Data Types.”

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

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