Case-insensitive replace with Mysql

Submitted by Anonymous (not verified) on Sun, 05/03/2009 - 18:14

Attention!!! This query will convert all matched records to lowercase, backup first!

UPDATE my_table SET my_text_field = REPLACE( LOWER(my_text_field), 'bad_string', 'good_string')
where my_text_field like '%bad_string%'

I tried to replace some spam-like words from a news queue. I tried this sql query above without where clause first. It was a big mistake because all queue converted to lowercase. I already read docs on mysql.man pages. But there is no function for a case-insensitive replace. I am still searching for a solution. Thanks for any help!

Add new comment