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() 函数非常易于使用。
以上就是哪个 MySQL 函数可用于附加带有单引号的列值?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!