MySQL REPEAT() Function

In MySQL, the REPEAT() function repeats the specified string the specified number of times.

REPEAT() Syntax

Here is the syntax of MySQL REPEAT() function:

REPEAT(str, count)

Parameters

str
Required. A string.
count
Required. The number of times.

Return value

The REPEAT(str, count) function returns a string consisting of the string str repeated count times.

  • If count is 0 or a negative value, the count function returns an empty string ''.
  • The function will return NULL if any parameter is NULL.

REPEAT() Examples

Here are some examples of MySQL REPEAT() function.

SELECT
    REPEAT('MySQL', 3),
    REPEAT('Go ', 3),
    REPEAT('MySQL', 0),
    REPEAT('MySQL', -1),
    REPEAT('MySQL', NULL),
    REPEAT(NULL, 3)\G
   REPEAT('MySQL', 3): MySQLMySQLMySQL
     REPEAT('Go ', 3): Go Go Go
   REPEAT('MySQL', 0):
  REPEAT('MySQL', -1):
REPEAT('MySQL', NULL): NULL
      REPEAT(NULL, 3): NULL

Note: If the number of times is 0, the function returns an empty string.