0

在 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 行是:返回响应;

4

1 回答 1

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 ;
于 2013-03-12T11:51:48.723 回答