DELIMITER $$
CREATE PROCEDURE usp_SetGems (p_requestid int, p_akcija int)
BEGIN
if(p_akcija=0)
then
declare v_userId int;
declare v_vingems decimal;
SELECT r.user_id INTO v_userId FROM Requests r WHERE r.Id=p_requestid;
end
$$
delimiter;
/* SQL 错误 (1064):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'declare v_userId int; 附近使用的正确语法。 声明 v_vingems 十进制; 在第 8 行选择 r.user_id INTO v_u' */
不知道问题出在哪里...
最佳答案
First declare all the variables than use if condition like this:
CREATE PROCEDURE usp_SetGems (p_requestid int, p_akcija int)
BEGIN
declare v_userId int;
declare v_vingems decimal;
if(p_akcija=0) then
SELECT r.user_id INTO v_userId FROM Requests r WHERE r.Id=p_requestid;
end
$$
delimiter;
关于mysql - 如何在 MySQL 中使用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36555318/