开发者

Updating fields in one table that are not empty

I got this SQL:

UPDATE users2 
SET picture = 'sites/site2/fil开发者_Go百科es/pictures/' + picture;
WHERE picture NOT IS NULL

And the only thing I get are that all picture fields get the value '0'.


Because adding does not work for strings. Use CONCAT() instead:

UPDATE users2 
SET picture = CONCAT('sites/site2/files/pictures/', picture)
WHERE pictures NOT IS NULL

Also, notice you have a semi-colon in the middle of the query... remove it or you'll get all rows updated!


In MySQL + means numerical addition. Your strings are being cast to integers, added, and then the result converted back to a string.

Use CONCAT for string concatenation. Here's a fixed version of your query:

UPDATE users2 
SET picture = CONCAT('sites/site2/files/pictures/', picture)
WHERE picture IS NOT NULL
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜