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">

Home  >  Article  >  Database  >  Which MySQL function can be used to append column values ​​with single quotes?

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

PHPz
PHPzforward
2023-08-26 15:45:181282browse

哪个 MySQL 函数可用于附加带有单引号的列值?

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

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)

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete