2016-03-30 22 views
-1

こんにちは、ansIDをパラメータとして取得し、UserテーブルとAnswerテーブルの両方の "score"フィールドを更新するプロシージャを作成しようとしています。ストアドプロシージャとMySQL変数

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 
+0

、問題は何ですか? – fancyPants

+0

が更新されました。ありがとう。 – RStyle

+0

あなたの 'SET'ステートメントに' SELECT'ステートメントを括弧で入れてください。 – fancyPants

答えて

1

使用のいずれか

SET @_userID = (SELECT user_id from Answers where id = _ansID); 

または

SELECT user_id from Answers where id = _ansID INTO @_userID; 
関連する問題