MySQL 变量声明中的语法错误
我有以下 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;
我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DECLARE
需要放在程序的第一行。来自文档:
DECLARE
s need to go on the first line of your procedure.From the docs: