Função para retirar acento no MySQL
Simples função para retirar acentos de caracteres do Banco de Dados.
CREATE FUNCTION retira_acento(Texto VARCHAR(500))
RETURNS varchar(500) CHARSET latin1
DETERMINISTIC
BEGIN
declare semAcento varchar(500);
SELECT lower(Texto) INTO semAcento;
SELECT REPLACE(semAcento,’ã’,’a’) INTO semAcento;
SELECT REPLACE(semAcento,’á’,’a’) INTO semAcento;
SELECT REPLACE(semAcento,’â’,’a’) INTO semAcento;
SELECT REPLACE(semAcento,’à’,’a’) INTO semAcento;
SELECT REPLACE(semAcento,’ê’,’e’) INTO semAcento;
SELECT REPLACE(semAcento,’é’,’e’) INTO semAcento;
SELECT REPLACE(semAcento,’ë’,’e’) INTO semAcento;
SELECT REPLACE(semAcento,’ï’,’i’) INTO semAcento;
SELECT REPLACE(semAcento,’í’,’i’) INTO semAcento;
SELECT REPLACE(semAcento,’ó’,’o’) INTO semAcento;
SELECT REPLACE(semAcento,’ô’,’o’) INTO semAcento;
SELECT REPLACE(semAcento,’ö’,’o’) INTO semAcento;
SELECT REPLACE(semAcento,’ú’,’u’) INTO semAcento;
SELECT REPLACE(semAcento,’ü’,’u’) INTO semAcento;
SELECT REPLACE(semAcento,’ç’,’c’) INTO semAcento;
SELECT REPLACE(semAcento,’ñ’,’n’) INTO semAcento;
SELECT REPLACE(semAcento,’\”,”) INTO semAcento;
SELECT REPLACE(semAcento,’´’,”) INTO semAcento;
SELECT REPLACE(semAcento,’`’,”) INTO semAcento;
SELECT REPLACE(semAcento,'”‘,”) INTO semAcento;
SELECT REPLACE(semAcento,’ ‘,”) INTO semAcento;
SELECT upper(SemAcento) INTO semAcento;
RETURN semAcento;
END;
Obs: Coloquei a linha SELECT REPLACE(semAcento,’ ‘,”) INTO semAcento; para retirar todos os espaços a mais que tenha na string, mesmo que entre uma palavra e outra.