Returns the length of str. Non-UTF-8 encoded strings return -1.
Syntax
bigint length(string <str>)Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
str | Yes | STRING | The 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.
| Condition | Return value |
|---|---|
str is a valid UTF-8 string | Number of characters |
str is null | null |
str is not UTF-8 encoded | -1 |
str is not a STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME type | Error |
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.