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

时间:2013-03-12 11:48:42

标签: mysql sql phpmyadmin

在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$$

我收到此错误:

  

#1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以获得正确的语法   靠近''第9行

第9行是:RETURN responce;

1 个答案:

答案 0 :(得分:0)

尝试使用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 ;