谢谢,但如果使用变量:::::这样:
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 是未知的,我怎么能解决这个问题
答案 0 :(得分:0)
为什么不呢:
insert into filesreferences (RefrenceKey, RefrenceCount) values (pRefrenceKey, 1)
on duplicate key update RefrenceCount= RefrenceCount+1;