
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- How can I use SPACE() function with MySQL WHERE clause?
- How can I use MySQL INTERVAL() function with a column of a table?
- How can I use MySQL IF() function within SELECT statement?
- How can I use IFNULL() function at the place of COALESCE() function in MySQL?
- How can I use MySQL IN() function to compare row constructors?
- 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 FIND_IN_SET() function with MySQL WHERE clause?
- How can we use MySQL INSTR() function with WHERE clause?
- How can we use MySQL SUM() function with HAVING clause?
- How can we use MySQL SUM() function?
- How can I use 2-digit year value in MySQL DATEDIFF() function?
- How can I use SPACE() function along with MySQL’s column data?
- In MySQL, how can we use FROM_UNIXTIME() function with format string?

Advertisements