user962449
user962449

Reputation: 3873

how to replace text using a query

How do I replace certain text in a field using sql?

Example Table:

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

How would I replace hello with hi in the field text while leaving the remaining text untouched?

Upvotes: 0

Views: 150

Answers (3)

RadBrad
RadBrad

Reputation: 7304

Select id, REPLACE(text,'hello','hi') AS text from table;

It's somewhat database dependent, but that should work on most databases.

Upvotes: 0

Yoav Kadosh
Yoav Kadosh

Reputation: 5155

as seen in this article

update TABLE_NAME set 
FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);

Upvotes: 1

Nesim Razon
Nesim Razon

Reputation: 9794

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

Upvotes: 2

Related Questions