[英]Stored procedure and MySQL Variable
Hi i am trying to create a procedure that gets the ansID as a param and updates the "score" field in both the User table and Answer Table.嗨,我正在尝试创建一个过程,该过程将 ansID 作为参数并更新用户表和答案表中的“分数”字段。
DELIMITER $$
CREATE PROCEDURE UpVoteAnswer(IN _ansID INT)
BEGIN
SET @_userID = SELECT user_id from Answers where id = _ansID;
UPDATE Answers SET score = score + 1 where id = _ansID;
UPDATE Users SET score = score + 1 where id = @_userID;
END
$$
DELIMITER ;
Error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT user_id from Answers where id = _ansID;
UPDATE Answers SET score = score' at line 3
Use either使用任一
SET @_userID = (SELECT user_id from Answers where id = _ansID);
or或者
SELECT user_id from Answers where id = _ansID INTO @_userID;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.