2016-04-11 41 views
0

Saklı yordamım için aşağıdaki kodu çalıştırmayı denedim ve satır 14'te hata atar. Hatanın yerini saptayamıyorum, çözmeme yardımcı olun.MySQL saklı yordamlar sözdizimi hatası

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

"İstekler" tablosunun yapısı nedir? – apokryfos

+0

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

+0

Değer ondalık ve user_id int, değişkenlerinizin veri türleriyle eşleşmiyor gibi görünüyorlar. – apokryfos

cevap

0

Kişisel Declare deyimi yanlış "içine" (; .....) @v_userId char (36 ilan, @v_vingems int beyan). Prosedürünüzün doğru kodu aşağıda verilmiştir: -

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

Seçtiğinizde ayrılmış bir sözcük var.

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

SELECT ... INTO 'yapmanın nesi yanlış? – apokryfos

+0

hala bir problem var, bunun @v_userId: = r.user_id gibi olması gerektiğini buldum ama işe yaramıyor * Sad_face_panda * – Dunster

+0

@apokryfos, Sorunu ve satır hatasını okudun mu? Bu seçimdeki "içine" kelimesinin doğru olmadığı açıktır. – dquinonez

İlgili konular