Suppose we want to make the output of the REPEAT() function more readable, then we can use it with other functions. For example, if we want to add spaces or other characters between repeated values, we can use the CONCAT() function.
mysql> Select REPEAT(CONCAT(' *',Subject,'* '),3)AS Subject_repetition from student; +-----------------------------------------+ | Subject_repetition | +-----------------------------------------+ | *Computers* *Computers* *Computers* | | *History* *History* *History* | | *Commerce* *Commerce* *Commerce* | | *Computers* *Computers* *Computers* | | *Math* *Math* *Math* | +-----------------------------------------+ 5 rows in set (0.00 sec)
In the following example, we use both the QUOTE() and CONCAT() functions with the REPEAT() function:
mysql> Select REPEAT(QUOTE(CONCAT(' *',Subject,'* ')),3)AS Subject_repetition from student; +-----------------------------------------------+ | Subject_repetition | +-----------------------------------------------+ | ' *Computers* '' *Computers* '' *Computers* ' | | ' *History* '' *History* '' *History* ' | | ' *Commerce* '' *Commerce* '' *Commerce* ' | | ' *Computers* '' *Computers* '' *Computers* ' | | ' *Math* '' *Math* '' *Math* ' | +-----------------------------------------------+ 5 rows in set (0.00 sec)
By using REPEAT() Functions and other functions we can make the output more readable.
The above is the detailed content of How to use other MySQL functions in the REPEAT() function?. For more information, please follow other related articles on the PHP Chinese website!