MySQL - Syntax Error in Stored Procedure using `if`

前端 未结 1 1375
别那么骄傲
别那么骄傲 2021-01-15 20:16

I need to know what is the error in the following stored procedure, as begging with mySql I can\'t understand what is the error

if not EXISTS( select filesr         


        
相关标签:
1条回答
  • 2021-01-15 20:56

    You have not used THEN keyword and 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;
    
    0 讨论(0)
提交回复
热议问题