Monday, November 5, 2007

Replace string in MySQL

Replacing a string in MySQL



So you have hundreds of records in a table, and you want to replace a string in a single query.
You could use the REPLACE MySQL function. Here is your replace query:

UPDATE yourtable SET yourfield = REPLACE(yourfield,"some_string","some_new_string")
WHERE yourconditions.

This query replaces "some_string" with "some_new_string" in "yourfield" field. You can also add some conditions in WHERE statement.

How to replace a string in mySQL

No comments: