Repeat Function In Sql in SQL
? REPEAT Function in SQL
The REPEAT() function repeats a string a specified number of times.
? Syntax:
REPEAT(string, number)string: The string you want to repeat.number: How many times to repeat it.
? Example:
SELECT REPEAT('SQL', 3) AS repeated_string;? Output:
| repeated_string |
|---|
| SQLSQLSQL |
? Example with space:
SELECT REPEAT('* ', 5) AS stars;Output:
| stars |
|---|
| * * * * * |
? Use Cases:
Creating padding or patterns
Repeating characters in formatting (e.g.,
'='50 times for a divider)
? Supported in: MySQL, MariaDB
? Not directly supported in: SQL Server or Oracle (but you can simulate with custom logic)
Want examples for other string functions like REPLACE(), CONCAT(), or REVERSE()?