

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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.
- Related Questions & Answers
- How can I use SPACE() function along with MySQL’s column data?
- How can I use SPACE() function with MySQL WHERE clause?
- How can I use MySQL IF() function within SELECT statement?
- How can I use MySQL INTERVAL() function with a column of a table?
- How can I use IFNULL() function at the place of COALESCE() function in MySQL?
- How can we use MySQL POWER() function with the column’s data values?
- How can I use MySQL IN() function to compare row constructors?
- How can we use MySQL SUM() function?
- How can we use MySQL INSTR() function with WHERE clause?
- How can we use FIND_IN_SET() function with MySQL WHERE clause?
- How can we use ASCII() function with MySQL WHERE clause?
- How can we use CHAR_LENGTH() function with MySQL WHERE clause?
- How can we use BIN() function with MySQL WHERE clause?
- How can we use MySQL SUM() function with HAVING clause?
- How can I use 2-digit year value in MySQL DATEDIFF() function?
Advertisements