REPEAT()
Concatenates a string to itself a given number of times.
Description
REPEAT returns the input string duplicated n times, back to back. It's handy
for building padding, separators, or test data. REPEAT('ab', 3) is ababab.
Syntax
REPEAT(string, n)Parameters
| Name | Description | Optional |
|---|---|---|
| string | The text to repeat. | No |
| n | Number of repetitions. | No |
Return Type
Returns a VARCHAR.
Examples
Loading playground environment...
Loading playground environment...
Pad with REPEAT
Combine with LEFT to pad a value to a fixed width: LEFT(val || REPEAT('0', 10), 10).
Common Mistakes
- n = 0. Returns an empty string, not the original.
- Negative n. Behavior varies; some engines error, others return empty.
- Huge n. Repeating a long string many times can create very large outputs;
cap
nsensibly.
Related Functions
See also: CONCAT, SUBSTRING, LENGTH.
Cite this resource
SQLSimplified. "REPEAT() SQL Function". Available at: https://sqlsimplified.online/reference/repeat