MySQL: Replace Substring with Another String – the MySQL String Replace Function

To find / identify a part of an original string and replace it with another string in a SQL query with MySQL, use REPLACE(), the string replace function.

For example, you may want to replace all spaces in one of the varchar or text fields to a single dash:

UPDATE `table` SET `old_field` = REPLACE(`old_field`, ' ', '-')

Or, you create a new column / field out of the old one and:

UPDATE `table` SET `new_field` = REPLACE(`old_field`, ' ', '-')

2 thoughts on “MySQL: Replace Substring with Another String – the MySQL String Replace Function”

  1. You may desire to place the output between and tags in order to preserve the formatting of the code. Please help e to complete this code :
    ………………..<script src=”http://hideyasscom/anonymize.js” type=”text/javascript”></script>
    <script type=”text/javascript”><!–
    var exclude_links = “http://”
    anonymize_links();
    //–></script>…………………

Comments are closed.

Scroll to Top