mySql ::一般变量错误中的错误

时间:2013-01-03 06:57:25

标签: mysql stored-procedures navicat

  

可能重复:
  MySQL - Syntax Error in Strored Procedure

谢谢,但如果使用变量:::::这样:

 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 是未知的,我怎么能解决这个问题

1 个答案:

答案 0 :(得分:0)

为什么不呢:

insert into filesreferences (RefrenceKey, RefrenceCount) values (pRefrenceKey, 1)
    on duplicate key update RefrenceCount= RefrenceCount+1;