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

by Yang Yang on May 16, 2009

Share This Article:
Subscribe to Kavoir: blog feed

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`, ' ', '-')
Share This Article:
Subscribe to Kavoir: blog feed

You should also read:

{ 2 comments… read them below or add one }

moely May 17, 2009 at 1:41 pm

i’m still waiting your help…

Reply

moely May 17, 2009 at 1:54 pm

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>…………………

Reply

Leave a Comment

Previous post:

Next post: