Sunday, April 17, 2011

Find and replace in mysql

For find and replace a text in a field is very easy in mysql. we can replace it with single query.
here is the find and replace query in mysql.


UPDATE your_tablename SET your_fieldname = REPLACE(your_fieldname,'your_search_string','your_replace_string');


using the above query you can easily replace the search string .
 The main drawback is it's case sensitive.


(ex)
UPDATE jos_content SET `fulltext` = replace( `fulltext` , 'Replace', 'test' ) WHERE id =1
using this find and replace query you just replace the string  'Replace' first letter caps lock. it will not replace "REPLACE", "replace" etc..



No comments:

Post a Comment