All Products
Search
Document Center

MaxCompute:LENGTHB

Last Updated:Jul 17, 2023

Returns the length of a string specified by str in bytes.

Syntax

bigint lengthb(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.

Examples

  • Example 1: Return the length of string Tech on the net in bytes. Sample statement:

    -- The return value is 15. 
    select lengthb('Tech on the net');
  • Example 2: The input parameter is set to null. Sample statement:

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

Related functions

LENGTHB is a string function. For more information about functions related to string searches and conversion, see String functions.