Updated on 2026-11-06 GMT+08:00

length

The length function is used to return the length of a string.

Similar function: lengthb. The lengthb function calculates the byte length of a string str.

Syntax

length(string ) 

Parameters

Parameter

Mandatory

Type

Description

str

Yes

STRING

The string whose length is to be calculated. If the input is of type BIGINT, DOUBLE, DECIMAL, or DATETIME, it is implicitly converted to STRING type before evaluation. Other types will return an error.

Return Values

Returns a value of type BIGINT.

  • If str is not of type STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME, an error is returned.
  • If str is NULL, NULL is returned.

Example Code

  • Calculate the length of the string abc. The command example is as follows.

    Returns 3.

    select length('abc');
  • The input parameter is NULL. The command example is as follows.

    Returns NULL.

    select length(null);