更新字符串部分的方法?

我正在寻找一种方法来更新只是一个字符串的一部分通过 MySQL 查询。

例如,如果我有10条记录,都包含‘ string’作为字段值的一部分(例如,‘ something/string’,‘ something/stringlookhere’,‘ something/string/etcetera’,有没有办法通过一个查询将每一行的‘ string’改为‘ another value’,以便结果是‘ something/another value’,‘ something/another valuellookhere’,‘ something/string/etcetera’,有没有办法改为‘ another value’

87077 次浏览
UPDATE `table` SET `field` = REPLACE(`field`, 'string', 'anothervalue')

Use the LIKE operator to find the rows that you care about and update them using the REPLACE function.

For example:

UPDATE table_name SET field_name = REPLACE(field_name,'search','replace') WHERE field_name LIKE '%some_value%'

I think this should work:

UPDATE table
SET field = REPLACE(field, 'string', 'anothervalue')
WHERE field LIKE '%string%';

Does something like this work in any way?

update table_name
set column_name = replace(column_name, 'string%', 'string')
where column_name like '%string%'