Skip to main content

MySQL REPLACE function

Posted on

MySQL always surprises me in the sheer amount of stuff you can do in it. For example I recently found it has a bunch of String Functions. The main one I found to be useful was the REPLACE function, which works like this:

REPLACE('Original String', 'Find This', 'Replace with this')

-- So it can be used like: --

SELECT REPLACE('My Original String', 'Original', 'Modified');
-- This will output: My Modified String --

-- So if you wanted to go through a full  table and replace a bunch of strings, you could use it like this: --

UPDATE `table_name` SET `field_name` = REPLACE(`field_name`, 'Find Me', 'Replace with Me');