replace substring in mysql fields
Filed in Development on Dec.10, 2008
Any webmaster face with a problem when he or she needs to change something due to updated details, for example, SKU#, phone number, or anything else that has been renamed and the change should be done in appropriate mysql table fields. Of course, you can open phpmyadmin and edit records one by one, but why not to use MySQL REPLACE function. It’s very simple. Assuming you need to replace ‘a’ with ‘b’ in column ‘title’ of table ‘table’:
UPDATE table SET title=REPLACE(title, 'a', 'b')
You can add WHERE condition if needed.
Alternatives in other programming languages:
Programming language | Function, method |
---|---|
PHP | str_replace |
JavaScript | replace |
Tags: mysql