7 maggio 2013

How-to: Remove special characters in String - Mysql

The only way to remove them is use the function REPLACE.

For example if you want remove following characters from a column in a table:

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

the statement will be:


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


Nessun commento: