Returns a string formed by repeating str exactly n times.
Syntax
string repeat(string <str>, bigint <n>)Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
str | Yes | STRING | The string to repeat. BIGINT, DOUBLE, DECIMAL, and DATETIME values are implicitly converted to STRING before the function runs. |
n | Yes | BIGINT | The number of times to repeat str. The result cannot exceed 2 MB in length. |
Return value
Returns a STRING value.
| Condition | Result |
|---|---|
str or n is null | null |
str is not STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME | Error |
n is not specified | Error |
Examples
Example 1: Repeat abc five times.
select repeat('abc', 5);
-- Return value: abcabcabcabcabcExample 2: Pass null as an argument.
select repeat('abc', null);
-- Return value: nullRelated functions
REPEAT is a string function. For more information about functions related to string searches and conversion, see String functions.