可能重复:
MySQL-选通过程中的语法错误
谢谢,但如果使用变量::::像这样:
IF NOT EXISTS( SELECT ReferenceID as ExistedRefID FROM filesrefrences WHERE RefrenceKey= pRefrenceKey) 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
它指的是执行错误ExistedRefID是未知的,我如何解决这个
为什么不只是:
insert into filesreferences (RefrenceKey, RefrenceCount) values (pRefrenceKey, 1)
on duplicate key update RefrenceCount= RefrenceCount+1;