变量声明中的MySQL语法错误

时间:2011-02-22 20:29:10

标签: mysql stored-procedures syntax variable-declaration

我有以下MySQL查询:

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//

我收到错误:

DECLARE winnerScore, loserScore INT;

我做错了什么?

1 个答案:

答案 0 :(得分:5)

DECLARE需要继续执行您的程序的第一行。

来自docs

  

只允许在一个内部使用DECLARE   BEGIN ... END复合语句和   必须在它开始之前,在任何其他之前   语句。