w3resource
MYSQL Tutorial

MySQL REPEAT() function

REPEAT() function

MySQL REPEAT() repeats a string for a specified number of times. Both the string and the number of times that string to be repeated are supplied as arguments.

The function returns NULL either any of the arguments is NULL.

Syntax:

REPEAT(str, count)

Arguments

Name Description
str A string which is to be repeated.
count An integer indicating how many times the string str is to be repeated.

Syntax Diagram:

MySQL REPEAT() Function - Syntax Diagram

MySQL Version: 5.6

Video Presentation

Example: MySQL REPEAT() function

The following MySQL statement repeats the string ‘**-‘ 15 times.

Code:

SELECT REPEAT('**-',15); 

Sample Output:

mysql> SELECT REPEAT('**-',15); 
+-----------------------------------------------+
| REPEAT('**-',15)                              |
+-----------------------------------------------+
| **-**-**-**-**-**-**-**-**-**-**-**-**-**-**- | 
+-----------------------------------------------+
1 row in set (0.03 sec)

All String Functions

MySQL String Functions, slide presentation