如何使用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