dimanche 4 octobre 2015

MySQL function if elseif 1064

I'm trying to use MySQL but since 2 days I'm stuck on it. I've got an 1064 error which mean syntax error. I tried a lot of things but none worked.

DELIMITER $$
CREATE FUNCTION set_libelle(civilite VARCHAR(4), prenom VARCHAR(30), nom VARCHAR(30)) 
RETURNS VARCHAR(20) 
    BEGIN
        IF (LEN(civilite)+LEN(prenom)+LEN(nom)<19) THEN
            RETURN civilite + ' ' + prenom + ' ' + nom;
        ELSEIF (LEN(civilite)+LEN(nom)<17) THEN 
            RETURN civilite + ' ' + LEFT(prenom,1) + '. ' + nom;
        ELSE 
            RETURN civilite + ' ' + LEFT(prenom,1) + '. ' + LEFT(nom, (17-(LEN(civilite)));
        END IF;
    END$$
DELIMITER ; 

Have you got an idea why this doesn't work ? Thank you

Aucun commentaire:

Enregistrer un commentaire