MySQL:使用命名值和位运算符更新SET字段 [英] MySQL: Update a SET field using named value and bit-operator
本文介绍了MySQL:使用命名值和位运算符更新SET字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于MySQL,是否可以使用字段的命名值和按位运算符之一来更新类型为SET的字段?示例:
For MySQL, is it possible to update a field of type SET using one of the field's named values and bitwise operators? Example:
假设 foo
为 SET('a','b',...)
,那么以下内容将不起作用:
Assume foo
to be SET('a', 'b',...)
,
then the following does not work:
UPDATE mytable SET foo = foo | 'a' WHERE ...
显然,只有 foo ='a'
或 foo = foo |1
工作.是否有任何技巧可以使上面的示例正常工作,并使MySQL意识到'a'
不是正常"字符串?我想避免使用幻数...非常感谢!
Apparently, only foo = 'a'
or foo = foo | 1
work. Is there any trick to get the above example working and make MySQL be aware of 'a'
being not a "normal" string? I'd like to avoid magic numbers... Many thanks!
推荐答案
UPDATE mytable SET foo = CONCAT_WS(',', foo, 'a') WHERE ...
这篇关于MySQL:使用命名值和位运算符更新SET字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文