LENGTH Function [String]

Returns the number of characters in the specified string.

Syntax

LENGTHstring-expression )

Parameters

Parameters

Parameter

Description

string-expression

The string.

Returns

INT

Example

The following statement returns the value 9:

SELECT LENGTH( 'chocolate' ) FROM iq_dummy

Usage

If the string contains multibyte characters, and the proper collation is being used, LENGTH returns the number of characters, not the number of bytes. If the string is of BINARY data type, the LENGTH function behaves as BYTE_LENGTH.

The LENGTH function is the same as the CHAR_LENGTH function.

Standards and Compatibility

  • SQL—Vendor extension to ISO/ANSI SQL grammar.

  • Sybase—Not supported by Adaptive Server Enterprise. Use the CHAR_LENGTH function instead.

Related reference
BIT_LENGTH Function [String]
BYTE_LENGTH Function [String]
CHAR_LENGTH Function [String]
COL_LENGTH Function [System]
DATALENGTH Function [System]
LEN Function [String]
OBJECT_NAME Function [System]
OCTET_LENGTH Function [String]
STR_REPLACE Function [String]