我在MySql(navicat)中有以下存储过程,但我需要测试 RefrenceCount 更新操作后,当我添加如果st。更新后的声明。发生语法错误
CREATE PROCEDURE `SP_IncDecReferenceCount`(pReferenceID int,pIncValue int)
BEGIN
update filesrefrences
set
filesrefrences.RefrenceCount= filesrefrences.RefrenceCount+pIncValue
where
filesrefrences.ReferenceID= pReferenceID;
IF Not EXISTS(SELECT * from filesrefrences where filesrefrences.ReferenceID= pReferenceID and filesrefrences.RefrenceCount>0) then
DELETE from filesrefrences WHERE filesrefrences.ReferenceID = pReferenceID;
end if
END
[Err] 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 'END' at line 11
答案 0 :(得分:0)
你可以做到
update filesrefrences
set
filesrefrences.RefrenceCount= filesrefrences.RefrenceCount+IF(pIncValue > 0,pIncValue,1)
where
filesrefrences.ReferenceID= pReferenceID;
OR
update filesrefrences
set
filesrefrences.RefrenceCount= filesrefrences.RefrenceCount+pIncValue
where
(filesrefrences.ReferenceID= pReferenceID) AND (pIncValue > 0);