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 get an error message:

 DECLARE winnerScore, loserScore INT; 

What am I doing wrong?

+6
syntax mysql stored-procedures variable-declaration
source share
1 answer

DECLARE needs to go to the first line of your procedure.

In docs :

DECLARE is only permitted inside BEGIN ... END is a composite application and must be at the very beginning before any other application.

+5
source share

All Articles