 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
 