Skip to content

Instantly share code, notes, and snippets.

@hornofj
Last active February 21, 2019 22:02
Show Gist options
  • Save hornofj/9be3b62966fdba861ee65bf6aea56e15 to your computer and use it in GitHub Desktop.
Save hornofj/9be3b62966fdba861ee65bf6aea56e15 to your computer and use it in GitHub Desktop.
Remove accents SQL
drop function if exists fn_remove_accents;
delimiter |
create function fn_remove_accents( textvalue varchar(20000) )
returns varchar(20000)
begin
set @textvalue = textvalue;
-- ACCENTS
set @withaccents = 'ĎŇňŘřČ莞ĽľĚ슚ŽžÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØßÙÚÛÜŮÝŸÞàáâãäåæçèéêëìíîïñòóôõöøùúûüůýÿþƒ';
set @withoutaccents = 'DdTtNnRrCcZzLlEeSsZzAAAAAAACEEEEIIIINOOOOOOsUUUUUYYBaaaaaaaceeeeiiiinoooooouuuuuyybf';
set @count = length(@withaccents);
while @count > 0 do
set @textvalue = replace(@textvalue, substring(@withaccents, @count, 1), substring(@withoutaccents, @count, 1));
set @count = @count - 1;
end while;
-- SPECIAL CHARS
set @special = '!@#$%¨&*()_+=§¹²³£¢¬"`´{[^~}]<,>.:;?/°ºª+*|\\''';
set @count = length(@special);
while @count > 0 do
set @textvalue = replace(@textvalue, substring(@special, @count, 1), '');
set @count = @count - 1;
end while;
return @textvalue;
end
|
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment