MySQL存储过程语法错误

MySQL存储过程语法错误,mysql,stored-procedures,Mysql,Stored Procedures,我试图为我的存储过程执行以下代码,它在第14行抛出错误。我无法找到什么是错误,请帮助我解决 DELIMITER $$ CREATE PROCEDURE usp_SetGems ( -- Add the parameters for the stored procedure here p_requestid int/* =null */, p_akcija int/* =null */) BEGIN -- SET NOCOUNT ON added to pr

我试图为我的存储过程执行以下代码,它在第14行抛出错误。我无法找到什么是错误,请帮助我解决

DELIMITER $$
   CREATE PROCEDURE usp_SetGems (
    -- Add the parameters for the stored procedure here
    p_requestid int/* =null */,
    p_akcija int/* =null */)
 BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.

    -- Insert statements for procedure here
    if p_akcija = 0 then

    declare @v_userId char(36);
    declare @v_vingems int;

    select @v_userId:=r.user_id, @v_vingems := r.value from Requests r
    where r.Id=p_requestid; 

    update Users 
    set balance=balance+@v_vingems
    where id=v_userId;

    else

    declare @v_userrId longtext;
    declare @v_vingemss int;

    select @v_userrId.user_id:=r.user_id, @v_vingemss := r.value from Requests r
    where r.Id=p_requestid;

    update Users 
    set balance=balance-@v_vingems
    where id=v_userrId;
    end if;
 end;  $$    
 DELIMITER ;

您的选择中有一个保留字。“进入”


您的Declare语句错误(Declare@v_userId char(36),Declare@v_vingems int;…)。以下是正确的程序代码:-

DELIMITER $$
   CREATE PROCEDURE usp_SetGems (
    -- Add the parameters for the stored procedure here
    p_requestid int/* =null */,
    p_akcija int/* =null */)
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.

    -- Insert statements for procedure here
    if p_akcija = 0 then
        BEGIN 
            select r.user_id, r.value INTO @v_userId, @v_vingems from Requests r
            where r.Id=p_requestid; 
            update Users 
            set balance=balance+@v_vingems
            where id=v_userId;
        END;
    else
        BEGIN 
            select r.user_id, r.value INTO @v_userId, @v_vingems from Requests r
            where r.Id=p_requestid; 

            update Users 
            set balance=balance-@v_vingems
            where id=v_userrId;
        END;
    end if;
 end $$ 
 DELIMITER ;

选择有什么不对。。。进入
?仍然存在一个问题,我发现它应该像@v_userId:=r.user_id,但它不起作用,悲伤的脸_panda@apokryfos,您是否阅读了问题和行错误?很明显,选择中的“进入”一词是不正确的。我编辑了这篇文章,现在代码看起来是这样的,我仍然有相同的代码problem@dquinonez这并不能回答我的问题,为什么有效的SQL会导致这个错误。
请求
表的结构是什么?@apokryfos值是十进制的,用户id是int,它们似乎与变量的数据类型不匹配。@apokryfos我将varchar改为int,int改为decimal,但仍然会遇到相同的错误尝试先将示例剥离到最小值,以排除错误在其他地方的可能性。例如,创建一个较小的过程,没有参数,只有2个声明和select,然后看看是否有效。
DELIMITER $$
   CREATE PROCEDURE usp_SetGems (
    -- Add the parameters for the stored procedure here
    p_requestid int/* =null */,
    p_akcija int/* =null */)
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.

    -- Insert statements for procedure here
    if p_akcija = 0 then
        BEGIN 
            select r.user_id, r.value INTO @v_userId, @v_vingems from Requests r
            where r.Id=p_requestid; 
            update Users 
            set balance=balance+@v_vingems
            where id=v_userId;
        END;
    else
        BEGIN 
            select r.user_id, r.value INTO @v_userId, @v_vingems from Requests r
            where r.Id=p_requestid; 

            update Users 
            set balance=balance-@v_vingems
            where id=v_userrId;
        END;
    end if;
 end $$ 
 DELIMITER ;