可以使用哪个MySQL函数将单引号的列的值追加?
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()
方法非常易于使用。