“响应”列中的数据为= blahblahblahTYPE=ERRORblahblah
。然后我运行下面的查询来定位'ERROR'字符串。
SELECT substr(Response, instr(Response, 'ERROR'), 5)
FROM table
WHERE id = 721451
AND Status = 'false'
AND Response LIKE '%<status>Unknown</status>%'
AND date >= curdate();
上面的查询返回:ERROR
。
我基本上想要将ERROR
更新为SUCCESS
而不修改其余数据。
下面的查询是否有效?有更好的方法吗?
UPDATE table
SET Response = 'SUCCESS'
WHERE (
SELECT substr(Response, instr(Response, 'ERROR'), 5)
FROM table
WHERE id = 721451
AND Status = 'false'
AND Response LIKE '%<status>Unknown</status>%'
AND date >= curdate()
);
提前感谢您的帮助!
答案 0 :(得分:1)
UPDATE table
SET Response = REPLACE(Response, 'ERROR', 'SUCCESS')
WHERE id = 721451
AND Status = 'false'
AND Response LIKE '%<status>Unknown</status>%'
AND date >= curdate();
参考https://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace