LENGTH

Returns the length of a string. The behavior of LENGTH varies according to the input data type:

  • CHAR and VARCHAR: Identical to CHARACTER_LENGTH, returns the string length in UTF-8 characters, .
  • CHAR: Strips padding.
  • BINARY and VARBINARY: Identical to OCTET_LENGTH, returns the string length in bytes (octets).

Behavior Type

Immutable

Syntax

LENGTH ( expression )

Parameters

expression

String to evaluate, one of the following: CHAR, VARCHAR, BINARY or VARBINARY.

Examples

Statement Returns
SELECT LENGTH('1234  '::CHAR(10));
4
SELECT LENGTH('1234  '::VARCHAR(10));
6
SELECT LENGTH('1234  '::BINARY(10));
10
SELECT LENGTH('1234  '::VARBINARY(10));
6
SELECT LENGTH(NULL::CHAR(10)) IS NULL;
t

See Also

BIT_LENGTH