views:

37

answers:

1

Does anyone have a code sample where I can to remove all special characters from data stored in MYSQL?

I need to remove the following special characters:

: ~!@#$%*()_+{}[];':"<>?

A: 

Try this... It looks terrible, but it works

SELECT * FROM Film where REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(Film.name,':',''),'~',''),'!',''),'@',''),'#',''),'$',''),'%',''),'*',''),'(',''),')',''),'_',''),'+',''),'{',''),'}',''),'[',''),']',''),';',''),'''',''),':',''),'"',''),'<',''),'>',''),'?','') = ?

This one will also strip out space:

SELECT * FROM Film where REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(Film.name,':',''),'~',''),'!',''),'@',''),'#',''),'$',''),'%',''),'*',''),'(',''),')',''),'_',''),'+',''),'{',''),'}',''),'[',''),']',''),';',''),'''',''),':',''),'"',''),'<',''),'>',''),'?',''),' ','') = ?
cjavapro
thanks , but is it cause many slow , in query ? because multi replace ....
meotimdihia
That is because it has to do the replace for every single row. Is it possible to add a special column `name_search` for the one without special characters? You could keep it up to date every night like this `UPDATE Film SET name_search = REPLACE....(name, ....)` Then you could run the search on name_search and the replacing will already be done. It would also allow you to use the LIKE operator and make better uses of indexes which would make things faster
cjavapro