Find and Replace in MySQL

I needed to do a find and replace on a couple of fields in a table and was stuck on the best way to this. Initially I was going to download a database dump and via a text editor find/replace and then re-upload but then I found out that MySQL has a Replace() function.

Posted: 12-Jul-2007

View: 6488

Permalink: here

Comments

What a coincidence!

I wrote a store procedure that does the same thing for MSSQL - see here: http://blog.richnetapps.com/index.php?title=search...

#1 Armand
12/Jul/07 5:08 PM

I'm pretty new to MySQL (from SQLServer) and I'm trying to figure out how to do an actual regex search in my where clause for (for example to ignore punctuation in peoples nicknames). I've (temporarily) been using Replace(Replace(table.nickname,'@#',''),'!','') but that's not really acceptable to do for so many characters. If I can figure out anything better thru my googling today I'll link it for ya!

#2 Joe Zack
12/Jul/07 6:08 PM

SQL server has a replace() function too. I'm not sure about Oracle, but I believe smething exists too

#3 Marcos Placona
13/Jul/07 7:28 AM

@Jack, MySQL has a regex function, check out REGEXP() at http://dev.mysql.com/doc/refman/5.0/en/string-comp...

#4 Andy J
13/Jul/07 7:49 AM

Great tip. Just used it. You could be posting these you know.

#5 William from Lagos
19/Jul/07 6:53 PM

Exactly what I was looking for! I didn't want to go through exporting sql and doing the search and replace in the file. I found software to do this but it's not free. Thanks for this tip!

#6 Bien
29/Sep/07 7:04 PM