All Products
Search
Document Center

MaxCompute:LENGTH

Last Updated:Mar 26, 2026

Returns the length of str. Non-UTF-8 encoded strings return -1.

Syntax

bigint length(string <str>)

Parameters

ParameterRequiredTypeDescription
strYesSTRINGThe string to measure. BIGINT, DOUBLE, DECIMAL, and DATETIME values are implicitly converted to STRING before the length is calculated.

Return value

Returns a BIGINT value.

ConditionReturn value
str is a valid UTF-8 stringNumber of characters
str is nullnull
str is not UTF-8 encoded-1
str is not a STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME typeError

Examples

Example 1: Return the length of a string.

-- The return value is 15.
select length('Tech on the net');

Example 2: Pass null as the input.

-- The return value is null.
select length(null);

Related functions

LENGTH is a string function. For more information about string search and conversion functions, see String functions.