我在以下存储过程中出现错误语法错误:
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;
错误是: [错误] 1064 - 您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第8行的''附近使用正确的语法
答案 0 :(得分: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 ;