6

我有以下 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;

我究竟做错了什么?

4

1 回答 1

6

DECLAREs 需要在程序的第一行进行。

文档

DECLARE 仅允许在 BEGIN ... END 复合语句中使用,并且必须位于其开头,在任何其他语句之前。

于 2011-02-22T20:32:16.633 回答