我想更新MYSQL中列的第一个字符
WHERE the format of the string is LIKE '1-%'
将第一个字符更改为“0”。
我创建了这个例子,并认为我在正确的轨道上......
UPDATE products
SET
has_roundel = REPLACE(has_roundel, SUBSTRING(has_roundel, 0, 1),'0')
WHERE
has_roundel like '1-%';
答案 0 :(得分:3)
MySQL SUBSTRING不是从0开始。
您可以使用:
UPDATE products
SET
has_roundel = REPLACE(has_roundel, SUBSTRING(has_roundel, 1, 1),'0')
WHERE
has_roundel like '1-%';
或者:
UPDATE products
SET
has_roundel = REPLACE(has_roundel, SUBSTRING(has_roundel, 1),'0')
WHERE
has_roundel like '1-%';
答案 1 :(得分:1)
尝试以下方法:
update products
set
has_roundel = concat('0', substring(has_roundel, 2))
where
has_roundel like '1-%';
答案 2 :(得分:1)
试试这个
UPDATE products
SET
has_roundel = REPLACE(has_roundel, LEFT(has_roundel,1),'0')
WHERE
has_roundel like '1-%';
或者:
UPDATE products
SET
has_roundel = Concat('0',SUBSTR(data, 2))
WHERE
has_roundel like '1-%';
答案 3 :(得分:0)
一种方法是使用CONCAT
UPDATE products
SET
has_roundel = CONCAT('0-', substring(has_roundel, 3))
WHERE
has_roundel like '1-%';