Categories
SQL / MySQL Tips and Tutorials

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`, ' ', '-')

By Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Kavoir.com? Shoot me a message.

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

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.