Skip to content
SQLSimplified
string

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

NameDescriptionOptional
stringThe text to repeat.No
nNumber of repetitions.No

Return Type

Returns a VARCHAR.

Examples

Employees & Departments

Loading database engine...

Employees & Departments

Loading database engine...

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 n sensibly.

See also: CONCAT, SUBSTRING, LENGTH.

Search

Search lessons, functions, examples, and practice problems