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

数据库数据库 2023-08-31 03:46:56 777
摘要: 假设我们希望使REPEAT()函数的输出更易读,那么我们可以与其他函数一起使用它。例如,如果我们想在重复的值之间添加空格或其他字符,我们可以使用CONCAT()函数。示例mysql>SelectREPEAT(CONCAT('*',Subject,&#3...

如何在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函数?的详细内容,更多请关注其它相关文章!