MySQL Syntax Error In Variable Declaration
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?
DECLARE
s 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.
精彩评论