最近新项目用的mysql 遇到的了一些问题记录下来
今天给数据库用户信息更新时,需要对某字符串中现有的值后面加新字符串。我用下面方式写的
update users set wx_openid=wx_openid+"___" where id=59
尴尬的是,出错了。出现异常
Truncated incorrect DOUBLE value:
经过搜索正确写法是通过CONCAT函数实现
concat()函数
功能:将多个字符串连接成一个字符串
语法:concat(str1, str2,…)
那么我们主题遇到的问题正确写法如下:
update users set wx_openid=CONCAT(wx_openid,"___") where id=59
如果想把新字符串加在前面,换个位置就可以了
update users set wx_openid=CONCAT("___",wx_openid) where id=59