Which MySQL function can be used to append values of a column with single quotes?


MySQL QUOTE() function can be used to append values of a column with single quotes. For this, we must have to pass column name as the argument of QUOTE() function. Data from ‘Student’ table is used to demonstrate it as follows

Example

mysql> Select Name, ID, QUOTE(Subject)AS Subject from Student;
+---------+------+-------------+
| Name    | ID   | Subject     |
+---------+------+-------------+
| Gaurav  | 1    | 'Computers' |
| Aarav   | 2    | 'History'   |
| Harshit | 15   | 'Commerce'  |
| Gaurav  | 20   | 'Computers' |
| Yashraj | 21   | 'Math'      |
+---------+------+-------------+
5 rows in set (0.00 sec)

In contrast, it can also be done with the help of CONCAT() function as follows −

mysql> Select Name, ID, CONCAT('''',Subject,'''')AS Subject from Student;
+---------+------+-------------+
| Name    | ID   | Subject     |
+---------+------+-------------+
| Gaurav  | 1    | 'Computers' |
| Aarav   | 2    | 'History'   |
| Harshit | 15   | 'Commerce'  |
| Gaurav  | 20   | 'Computers' |
| Yashraj | 21   | 'Math'      |
+---------+------+-------------+
5 rows in set (0.00 sec)

For this purpose QUOTE() function is very easy to use.

Sai Subramanyam
Sai Subramanyam

Passionate, Curious and Enthusiastic.

Updated on: 30-Jul-2019

54 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements