Friday, December 20, 2024

MySQL REPEAT() Function

 The REPEAT() function in MySQL is used to repeat a given string a specified number of times. It takes two arguments:

  1. The string that you want to repeat.
  2. The number of times you want to repeat it.

Syntax:

REPEAT(string, count)
  • string: The string you want to repeat.
  • count: The number of times to repeat the string.

Example:

SELECT REPEAT('abc', 3);

This will return:

abcabcabc

In this example, the string 'abc' is repeated 3 times.

Notes:

  • If count is less than or equal to 0, the function will return an empty string.
  • If string is an empty string, the result will also be an empty string, regardless of the value of count.

No comments:

Post a Comment