哪种 MySQL 函数可用于将带有单引号的值附加到某列?
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() 函数非常易于使用。
广告