MySQL Forums
Forum List  »  Stored Procedures

A stored function to remove diacritics and other chars
Posted by: Marc Elbet
Date: December 10, 2015 08:45AM

Hi,

I tried to write the following function to get rid of diacritics and other special characters.
It looks OK but it is rejected whatever changes I make to the syntax.
I use phpMyAdmin as the interface.

Any help will be much appreciated to tell me what is wrong in my code.
The last part with the IF and WHILE loops may be redundant but it is not what generates the issue.

HERE IT IS ....

CREATE FUNCTION No_fancy_char ( String_in VARCHAR(90) ) RETURNS VARCHAR(90)
DECLARE @i int
DECLARE @String_in VARCHAR(90)
DECLARE @String_out VARCHAR(90)
SET @i=1
SET @String_out=''
SET @String_in = LOWER(String_in);
SET @String_in = REPLACE(@String_in,' ', '')
SET @String_in = REPLACE(@String_in,'à', 'a')
SET @String_in = REPLACE(@String_in,'â', 'a')
SET @String_in = REPLACE(@String_in,'è', 'e')
SET @String_in = REPLACE(@String_in,'é', 'e')
SET @String_in = REPLACE(@String_in,'ë', 'e')
SET @String_in = REPLACE(@String_in,'ì', 'i')
SET @String_in = REPLACE(@String_in,'î', 'i')
SET @String_in = REPLACE(@String_in,'ï', 'i')
SET @String_in = REPLACE(@String_in,'ò', 'o')
SET @String_in = REPLACE(@String_in,'ù', 'u')
SET @String_in = REPLACE(@String_in,'û', 'u')
SET @String_in = REPLACE(@String_in,'ç', 'c')
SET @String_in = REPLACE(@String_in,'$', '')
SET @String_in = REPLACE(@String_in,'£', '')
SET @String_in = REPLACE(@String_in,'€', '')
SET @String_in = REPLACE(@String_in,'''', '')
SET @String_in = REPLACE(@String_in,'"', '')
SET @String_in = REPLACE(@String_in,':', '')
SET @String_in = REPLACE(@String_in,'`', '')
SET @String_in = REPLACE(@String_in,'-', '')
SET @String_in = REPLACE(@String_in,'+', '')
SET @String_in = REPLACE(@String_in,'(', '')
SET @String_in = REPLACE(@String_in,')', '')
SET @String_in = REPLACE(@String_in,'?', '')
SET @String_in = REPLACE(@String_in,'!', '')
SET @String_in = REPLACE(@String_in,'#', '')
WHILE @i <= Len(@String_in)
BEGIN
IF SUBSTRING(@String_in, @i, 1) LIKE '[a-Z]'
BEGIN
SET @String_out = @String_out + SUBSTRING(@String_in, @i, 1)
END
SET @i = @i + 1
END
RETURN @String_out
END

AND HERE IS THE MESSAGE I GET

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE @i INT
DECLARE @String_in VARCHAR(90)
DECLARE @String_out VARCHAR(' at line 2

Thanks a lot.

Marc.

Options: ReplyQuote


Subject
Views
Written By
Posted
A stored function to remove diacritics and other chars
4065
December 10, 2015 08:45AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.