#1064 - 您的SQL语法有错误;找不到语法错误

时间:2022-04-24 14:26:57

in phpMyAdmin 3.5.1 I wrote :

在phpMyAdmin 3.5.1我写道:

DELIMITER $$
CREATE DEFINER=`root`@`localhost` FUNCTION  `getconjointthismariage`(idmember smallint(5) unsigned, mariageidconjoint smallint(5) unsigned) RETURNS varchar(200) CHARSET utf8
BEGIN
DECLARE responce varchar(200);
SELECT CONCAT(" (a épousé ", IF( `members`.`deces_date` IS NOT NULL , "† ", "" ) , CONCAT_WS(" ", `members`.`prenom` , `members`.`nom`), ")") INTO responce
FROM `mariages`
LEFT JOIN `members` ON `members`.`id` = mariageidconjoint
WHERE (`mariages`.`id_member` = idmember AND `mariages`.`id_conjoint` = mariageidconjoint);
RETURN responce;
END$$

and i get this error :

我得到这个错误:

#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 '' at line 9

#1064 - 您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在第9行附近使用正确的语法

Line 9 is : RETURN responce;

第9行是:RETURN响应;

1 个解决方案

#1


0  

Try using SET,

尝试使用SET,

DELIMITER $$

CREATE FUNCTION  `getconjointthismariage`
(
    idmember smallint(5) unsigned, 
    mariageidconjoint smallint(5) unsigned
) 
RETURNS varchar(200) CHARSET utf8
BEGIN

    DECLARE responce varchar(200);

    SET responce =
        (SELECT CONCAT(' (a épousé ', IF( `members`.`deces_date` IS NOT NULL , '† ') , CONCAT_WS(' ', `members`.`prenom` , `members`.`nom`), ')') 
        FROM    `mariages`
                LEFT JOIN `members` 
                    ON `members`.`id` = mariageidconjoint -- <<== PLEASE DO CHECK THIS CONDITION
        WHERE   `mariages`.`id_member` = idmember AND 
                `mariages`.`id_conjoint` = mariageidconjoint);

    RETURN responce;

END$$

DELIMITER ;

#1


0  

Try using SET,

尝试使用SET,

DELIMITER $$

CREATE FUNCTION  `getconjointthismariage`
(
    idmember smallint(5) unsigned, 
    mariageidconjoint smallint(5) unsigned
) 
RETURNS varchar(200) CHARSET utf8
BEGIN

    DECLARE responce varchar(200);

    SET responce =
        (SELECT CONCAT(' (a épousé ', IF( `members`.`deces_date` IS NOT NULL , '† ') , CONCAT_WS(' ', `members`.`prenom` , `members`.`nom`), ')') 
        FROM    `mariages`
                LEFT JOIN `members` 
                    ON `members`.`id` = mariageidconjoint -- <<== PLEASE DO CHECK THIS CONDITION
        WHERE   `mariages`.`id_member` = idmember AND 
                `mariages`.`id_conjoint` = mariageidconjoint);

    RETURN responce;

END$$

DELIMITER ;