Home > Database > Mysql Tutorial > body text

How to use other MySQL functions in the REPEAT() function?

王林
Release: 2023-08-23 14:07:57
forward
968 people have browsed it

How to use other MySQL functions in the REPEAT() function?

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.

Example

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!