如何使用sql替换字段中的某些文本?如何使用查询替换文本
示例表:
id text
-------------------------------
1 hello my name is keven
2 hello my name is steve
3 hi my name is sam
我怎么会在现场与text
取代hi
而hello
留下剩余的文本不变?
如何使用sql替换字段中的某些文本?如何使用查询替换文本
示例表:
id text
-------------------------------
1 hello my name is keven
2 hello my name is steve
3 hi my name is sam
我怎么会在现场与text
取代hi
而hello
留下剩余的文本不变?
UPDATE YOUR_TABLE SET `text` = REPLACE(`text`, 'hello', 'hi')
所看到的这个article
update TABLE_NAME set
FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);
Select id, REPLACE(text,'hello','hi') AS text from table;
这有点依赖于数据库的,但应该在大多数数据库工作。
可能重复的[SQL搜索和替换在MySQL中](http://stackoverflow.com/questions/421227/sql-to-search-and-replace-in-mysql) – 2012-04-22 20:41:04