开发者

MySQL Syntax Error In Variable Declaration

开发者 https://www.devze.com 2023-02-12 12:28 出处:网络
I have the following MySQL query: DELIMITER // CREATE PROCEDURE InsertResult (IN winnerID INT, IN loserID INT)

I have the following MySQL query:

DELIMITER //
CREATE PROCEDURE InsertResult (IN winnerID INT, IN loserID INT)
BEGIN
    INSERT INTO KomperResult (WinnerID, LoserID) VALUES (@winnerID, @loserID);
    DECLARE winnerScore, loserScore INT;
    SELECT Score INTO @winnerScore FROM KomperPerson WHERE ID = @winnerID;
    SELECT Score INTO @loserScore FROM KomperPerson WHERE ID = @loserID;
    IF (@loserScore >= @winnerScore) THEN UPDATE KomperPerson SET Score = @loserScore + 1 WHERE ID = @winnerID; END IF;
END//

I g开发者_开发问答et an error on:

DECLARE winnerScore, loserScore INT;

What am I doing wrong?


DECLAREs need to go on the first line of your procedure.

From the docs:

DECLARE is permitted only inside a BEGIN ... END compound statement and must be at its start, before any other statements.

0

精彩评论

暂无评论...
验证码 换一张
取 消