2016-04-11 21 views
0

私はストアドプロシージャのコードを以下に実行しようとしていますが、行番号14にエラーがスローされます。エラーが見つかりませんでした。MySQLストアドプロシージャの構文エラー

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 [email protected]_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 [email protected]_vingems 
    where id=v_userrId; 
    end if; 
end; $$  
DELIMITER ; 
+0

'Requests'テーブルの構造は何ですか? – apokryfos

+0

@apokryfos http://prntscr.com/aqxr4o – Dunster

+0

値は小数で、user_idはintで、変数のデータ型と一致していないようです。 – apokryfos

答えて

0

あなたのDeclareステートメント "には、"(; ..... @v_vingemsはint型を宣言、@v_userIdはchar(36)を宣言)間違っています。以下はプロシージャの正しいコードです: -

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 [email protected]_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 [email protected]_vingems 
      where id=v_userrId; 
     END; 
    end if; 
end $$ 
DELIMITER ; 
0

あなたの選択には予約語があります。

select r.user_id,r.value **into** v_userrId, v_vingems from Requests r 
where r.Id=p_requestid; 
+0

'SELECT ... INTO 'のやり方は何ですか? – apokryfos

+0

まだ問題がある、私はそれが@v_userId:= r.user_idのようにすべきであることがわかったが、動作しない* sad_face_panda * – Dunster

+0

@apokryfos、問題と行のエラーを読んだか?そのselectの中の "into"という単語が正しくないことは明らかです。 – dquinonez