SelectName,ID,QUOTE(Subject)ASSubjectfromStudent;+---------+------+--------- ----+|Name|ID|Subject|+---------+------+-------------+|Gaurav|1|' Computers'||Aarav|2|'His"/> SelectName,ID,QUOTE(Subject)ASSubjectfromStudent;+---------+------+--------- ----+|Name|ID|Subject|+---------+------+-------------+|Gaurav|1|' Computers'||Aarav|2|'His">
MySQL QUOTE() function can be used to append column values with single quotes. To do this, we have to pass the column name as an argument to the QUOTE() function. The following uses data from the "Student" table to demonstrate
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)
On the contrary, it can also be done with the help of the CONCAT() function, as shown below -
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)
The QUOTE() function is very easy to use for this purpose.
The above is the detailed content of Which MySQL function can be used to append column values with single quotes?. For more information, please follow other related articles on the PHP Chinese website!