Friday, October 1, 2010

mysql string search and replace

UPDATE [tablename] SET [fieldname] = REPLACE([fieldname],"[oldstring]","[newstring]");

The code above would operate on every row in the table but you may want WHERE conditions. Example:
UPDATE profile SET homepage = REPLACE(homepage,"","") WHERE first_name="Joe" AND last_name="Schmoe";

Will change Joe's homepage to instead of

No comments:

Post a Comment