MySql - 更新字符串部分的方法? [英] MySql - Way to update portion of a string?

查看:49
本文介绍了MySql - 更新字符串部分的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm looking for a way to update just a portion of a string via MySQL query.

例如,如果我有 10 条记录,所有记录都包含字符串"作为字段值的一部分(即,某事/字符串"、某事/字符串看这里"、某事/字符串/等",有没有办法通过一个查询将每一行的 'string' 更改为 'anothervalue',以便结果是 'something/anothervalue'、'something/anothervaluelookhere'、'something/string/etcetera',有没有办法改变 'anothervalue'

For example, if I have 10 records all containing 'string' as part of the field value (i.e., 'something/string', 'something/stringlookhere', 'something/string/etcetera', is there a way to change 'string' to 'anothervalue' for each row via one query, so that the result is 'something/anothervalue', 'something/anothervaluelookhere', 'something/string/etcetera', is there a way to change 'anothervalue'

推荐答案

我认为这应该可行:

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

这篇关于MySql - 更新字符串部分的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆