MySQL: REPEAT Function
This MySQL tutorial explains how to use the MySQL REPEAT function with syntax and examples.
Description
The MySQL REPEAT function repeats a string a specified number of times.
Syntax
The syntax for the REPEAT function in MySQL is:
REPEAT( string, number )
Parameters or Arguments
- string
- The string to repeat.
- number
- The number of times to repeat the string.
Note
- If number is less than 1, the REPEAT function will return an empty string.
Applies To
The REPEAT function can be used in the following versions of MySQL:
- MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23
Example
Let's look at some MySQL REPEAT function examples and explore how to use the REPEAT function in MySQL.
For example:
mysql> SELECT REPEAT('A', 2); Result: 'AA' mysql> SELECT REPEAT('a', 5); Result: 'aaaaa' mysql> SELECT REPEAT('abc', 2); Result: 'abcabc' mysql> SELECT REPEAT(' ', 6); Result: ' ' mysql> SELECT REPEAT(3, 2); Result: '33' mysql> SELECT REPEAT('abc', 0); Result: ''
Advertisements