MySQL Search and Replace
Searching and replacing specific text within a table field is a common task in database management. In MySQL, a specific query can efficiently perform this operation.
Query:
UPDATE table_name SET field = REPLACE(field, 'foo', 'bar') WHERE INSTR(field, 'foo') > 0;
Explanation:
Example:
Consider a table named 'example_table' with a field named 'description' containing the record 'hello foo'. To replace 'foo' with 'bar' in this record, use the following query:
UPDATE example_table SET description = REPLACE(description, 'foo', 'bar') WHERE INSTR(description, 'foo') > 0;
After executing the query, the description field for the specified record will be updated to 'hello bar'.
Note:
The above is the detailed content of How to Use MySQL's REPLACE Function for Case-Insensitive Search and Replace?. For more information, please follow other related articles on the PHP Chinese website!