DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Chara has posted 50 posts at DZone. View Full User Profile

Find and Replace with MySQL

  • submit to reddit
-- 1st example
UPDATE files SET filepath = REPLACE(filepath,'path/to/search','path/to/replace');
-- 2nd example
UPDATE customers SET address = REPLACE(address,'_CODE_',postcode);

MySQL has a handy and simple string function REPLACE() that allows table data with the matching string to be replaced by new string. This is useful if there is need to search and replace a text string which affects many records or rows, such as change of address, company name, URL or spelling mistake.