Creating a function

[expired user #9509]'s profile image [expired user #9509] posted 8 years ago in General Permalink

Hi !

I'm trying to create a function in my database, but the editor is giving me an error. Someone could please help me discovering where is the error ?

CREATE FUNCTION `urlAmigavel` (`name` VARCHAR(255))
RETURNS VARCHAR(50) CHARSET utf8
LANGUAGE SQL
DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
DECLARE campo VARCHAR(255); 
SET campo = TRIM(UCASE(name));  
    SET campo = REPLACE(campo ,'Á','A');  
    SET campo = REPLACE(campo ,'À','A');  
    SET campo = REPLACE(campo ,'Ã','A');  
    SET campo = REPLACE(campo ,'Â','A');  
    SET campo = REPLACE(campo ,'É','E');  
    SET campo = REPLACE(campo ,'È','E');  
    SET campo = REPLACE(campo ,'Ê','E');  
    SET campo = REPLACE(campo ,'Í','I');  
    SET campo = REPLACE(campo ,'Ì','I');  
    SET campo = REPLACE(campo ,'Î','I');  
    SET campo = REPLACE(campo ,'Ó','O');  
    SET campo = REPLACE(campo ,'Ò','O');  
    SET campo = REPLACE(campo ,'Ô','O');  
    SET campo = REPLACE(campo ,'Õ','O');  
    SET campo = REPLACE(campo ,'Ú','U');  
    SET campo = REPLACE(campo ,'Ù','U');  
    SET campo = REPLACE(campo ,'Û','U');  
    SET campo = REPLACE(campo ,'Ü','U');  
    SET campo = REPLACE(campo ,'Ç','C');  
    SET campo = REPLACE(campo ,'  ','-');  
    SET campo = REPLACE(campo ,' ','-');  
    SET campo = REPLACE(campo ,'+','');  
    SET campo = REPLACE(campo ,'_-_','-');  
    SET campo = REPLACE(campo ,'/','');  
    SET campo = REPLACE(campo ,'\\','');
    SET campo = REPLACE(campo ,'%','%25');
    RETURN LCASE(campo);
END

Thanks and sorry for the horrible english.

1 attachment(s):
  • sql-error
ansgar's profile image ansgar posted 8 years ago Permalink

Just remove the CREATE FUNCTION... up to but excluding the BEGIN from the body. HeidiSQL's procedure editor creates these meta details via GUI controls. The routine body expects something wrapped in BEGIN ... END

[expired user #9509]'s profile image [expired user #9509] posted 8 years ago Permalink

is working ! Thanks.

Please login to leave a reply, or register at first.