Returns the length of the string str.
Syntax
bigint length(string <str>)
Parameters
str: required. A value of the STRING type. If the input value is of the BIGINT, DOUBLE, DECIMAL, or DATETIME type, the value is implicitly converted into a value of the STRING type before calculation.
Return value
A value of the BIGINT type is returned. The return value varies based on the following rules:
If the value of str is not of the STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME type, an error is returned.
If the value of str is null, null is returned.
If the value of str is not UTF-8 encoded, -1 is returned.
Examples
Example 1: Return the length of the string
Tech on the net
. Sample statement:-- The return value is 15. select length('Tech on the net');
Example 2: An input parameter is set to null. Sample statement:
-- The return value is null. select length(null);
Related functions
LENGTH is a string function. For more information about functions related to string searches and conversion, see String functions.