我需要知道以下存储过程中的错误是什么,因为mySql乞求我无法理解错误是什么
if not EXISTS( select filesrefrences.ReferenceID from filesrefrences where filesrefrences.RefrenceKey= pRefrenceKey)
BEGIN
Insert into filesrefrences
(
filesrefrences.RefrenceKey,
filesrefrences.RefrenceCount
)
VALUES
(
pRefrenceKey,
1
);
select LAST_INSERT_ID();
END
ELSE
BEGIN
UPDATE filesrefrences
set filesrefrences.RefrenceCount= filesrefrences.RefrenceCount+1
WHERE filesrefrences.ReferenceID= ExistedReferenceID;
SELECT ExistedReferenceID;
END
第4行出现错误
您没有使用THEN关键字和END IF。
Try this:
SET @ExistedRefID = NULL;
SELECT ReferenceID INTO @ExistedRefID
FROM filesrefrences
WHERE RefrenceKey= pRefrenceKey;
IF (@ExistedRefID IS NULL) THEN
INSERT INTO filesrefrences(RefrenceKey, RefrenceCount)
VALUES(pRefrenceKey,1);
SELECT LAST_INSERT_ID();
ELSE
UPDATE filesrefrences
SET RefrenceCount= RefrenceCount+1
WHERE ReferenceID= @ExistedRefID;
SELECT @ExistedRefID;
END IF;