0

我在以下存储过程中有错误语法错误:

DROP PROCEDURE IF EXISTS `SP_IncDecReferenceCount`;
CREATE DEFINER = `root`@`localhost` PROCEDURE `SP_IncDecReferenceCount`(pReferenceID int)
BEGIN
IF EXISTS(SELECT * from filesrefrences where filesrefrences.ReferenceID= pReferenceID and filesrefrences.RefrenceCount>1) then 
update filesrefrences
set 
    filesrefrences.RefrenceCount= filesrefrences.RefrenceCount-1
where 
        filesrefrences.ReferenceID= pReferenceID;
SELECT pReferenceID;
ELSE IF EXISTS(SELECT * from filesrefrences where filesrefrences.ReferenceID= pReferenceID) then 
DELETE from filesrefrences WHERE filesrefrences.ReferenceID = pReferenceID;
SELECT -77;
ELSE
SELECT -99;
end if ;
END;

错误是:[Err] 1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 8 行的 '' 附近使用正确的语法

4

1 回答 1

0

你需要改变DELIMITER. 例如,

DROP PROCEDURE IF EXISTS `SP_IncDecReferenceCount`;

DELIMITER &&

CREATE PROCEDURE `SP_IncDecReferenceCount`(pReferenceID int)
BEGIN
    IF EXISTS(SELECT * from filesrefrences where filesrefrences.ReferenceID= pReferenceID and filesrefrences.RefrenceCount>1) then 
        update filesrefrences
        set 
            filesrefrences.RefrenceCount= filesrefrences.RefrenceCount-1
        where 
                filesrefrences.ReferenceID= pReferenceID;
        SELECT pReferenceID;
    ELSE IF EXISTS(SELECT * from filesrefrences where filesrefrences.ReferenceID= pReferenceID) then 
        DELETE from filesrefrences WHERE filesrefrences.ReferenceID = pReferenceID;
        SELECT -77;
    ELSE
        SELECT -99;
    end if ;
END &&

DELIMITER ;
于 2013-01-06T06:17:20.490 回答