All Products
Search
Document Center

MaxCompute:REPEAT

Last Updated:Jul 24, 2023

Returns a string that repeats the string specified by str for n times.

Syntax

string repeat(string <str>, bigint <n>)

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.

  • n: required. A value of the BIGINT type. The returned string cannot exceed 2 MB in length.

Return value

A value of the STRING 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 n is left empty, an error is returned.

  • If the value of str or n is null, null is returned.

Examples

  • Example 1: Return a string that repeats the string abc for 5 times. Sample statement:

    -- The return value is abcabcabcabcabc. 
    select repeat('abc', 5); 
  • Example 2: An input parameter is set to null. Sample statement:

    -- The return value is null. 
    select repeat('abc', null);

Related functions

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