Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How can I use another MySQL function/s with REPEAT() function?
Suppose if we want to make the output of REPEAT() function more readable then we can use another function/s with it. For example, if we want to add space or some other character between the repeated values then we can use 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)
In the example below, we are using QUOTE() and CONCAT() function both with 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)
In this way, by using other function/s with REPEAT() function, we can make the output more readable.
Advertisements
