如何在REPEAT()函数中使用其他的MySQL函数?

王林
王林 转载
2023-08-23 14:07:57 655浏览

如何在REPEAT()函数中使用其他的MySQL函数?

假设我们希望使REPEAT()函数的输出更易读,那么我们可以与其他函数一起使用它。例如,如果我们想在重复的值之间添加空格或其他字符,我们可以使用CONCAT()函数。

示例

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)

在下面的示例中,我们同时使用了QUOTE()和CONCAT()函数与REPEAT()函数:

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)

通过使用REPEAT()函数与其他函数,我们可以使输出更易读。

以上就是如何在REPEAT()函数中使用其他的MySQL函数?的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:tutorialspoint,如有侵犯,请联系admin@php.cn删除