MySQLQUOTE()
函数可用于在单引号后面附加一列的值。为此,我们必须将列名作为QUOTE()
函数的参数传递。“学生”表中的数据用于演示如下
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()
方法非常易于使用。