我将数值变量存储在字符串中。类似:165,37,0,0,21
现在我只需要更改最后一部分,其余部分保持不变。(在我的例子中,我需要将21更改为0(
你有什么想法吗?
我建议使用正则表达式,下面的reg ex将在字符串末尾找到数字,包括最后一个逗号,并将其替换为',0'
UPDATE table SET column1 = REGEXP_REPLACE(column1 , ',[0-9]*$', ',0')
REPLACE在这种情况下是最理想的:
UPDATE tbl_name
SET
field_name = REPLACE(field_name,
string_to_find, -- in your case 21
string_to_replace -- in your case 0 )
WHERE
<place condition if any e.g. the key to that record>;