Created
February 2, 2014 09:32
-
-
Save apphp/8765319 to your computer and use it in GitHub Desktop.
Find and Replace with MySQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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. | |
Source: http://www.apphp.com/index.php?snippet=mysql-find-and-replace | |
*/ | |
-- 1st example | |
UPDATE files SET filepath = REPLACE(filepath,'path/to/search','path/to/replace'); | |
-- 2nd example | |
UPDATE customers SET address = REPLACE(address,'_CODE_',postcode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment