Find and Replace in MySQL
I needed to do a find and replace on a couple of fields in a table and was stuck on the best way to this. Initially I was going to download a database dump and via a text editor find/replace and then re-upload but then I found out that MySQL has a Replace() function.
All you need to do is
1UPDATE yourTable SET yourField = replace(yourField,from_str,to_str);
The "from_str" performs a case-sensitive match when searching! Obviously you can also expand this to add any other logic like a WHERE clause etc.
This probably works with other DB's ... I would of thought anyway
| Tweet |
| If you like what you see on the website and/or this post has helped you out in some way please consider donating to help keep me in beer vodka. The donations are made through Paypal, which accepts almost any credit card or eCheck. |
I wrote a store procedure that does the same thing for MSSQL - see here: http://blog.richnetapps.com/index.php?title=search...