2012-04-22 54 views
0

如何使用sql替換字段中的某些文本?如何使用查詢替換文本

示例表:

id    text 
------------------------------- 
1  hello my name is keven 
2  hello my name is steve 
3  hi my name is sam 

我怎麼會在現場與text取代hihello留下剩餘的文本不變?

+0

可能重複的[SQL搜索和替換在MySQL中](http://stackoverflow.com/questions/421227/sql-to-search-and-replace-in-mysql) – 2012-04-22 20:41:04

回答

2
UPDATE YOUR_TABLE SET `text` = REPLACE(`text`, 'hello', 'hi') 
1

所看到的這個article

update TABLE_NAME set 
FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’); 
0
Select id, REPLACE(text,'hello','hi') AS text from table; 

這有點依賴於數據庫的,但應該在大多數數據庫工作。