如何使用 sql 替换字段中的某些文本?
示例表:
id text
-------------------------------
1 hello my name is keven
2 hello my name is steve
3 hi my name is sam
在保持剩余文本不变的情况下,如何在字段中hello
替换为?hi
text
UPDATE YOUR_TABLE SET `text` = REPLACE(`text`, 'hello', 'hi')
如本文所示
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;
它在某种程度上依赖于数据库,但这应该适用于大多数数据库。