Home > Database > Mysql Tutorial > 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
Release: 2023-08-26 15:45:18
forward
1299 people have browsed it

哪个 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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template