哪个 MySQL 函数可用于将列的值附加到单引号中?
mysqlmysqli database
MySQL QUOTE() 函数可用于将列的值附加到单引号中。为此,我们必须将列名作为 QUOTE() 函数的参数传递。来自"Student"表的数据用于演示如下
示例
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)
相反,也可以借助 CONCAT() 函数完成,如下所示 −
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)
为此目的,QUOTE() 函数非常容易使用。