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 get 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With