mysql触发imbricate如果

时间:2014-12-21 16:01:38

标签: mysql triggers

我仍然是mysql触发器的新手,所以我想对我最近遇到的问题有一些帮助。 这是我所做的触发器。

delimiter |
CREATE TRIGGER Test_001 AFTER INSERT ON reponse
FOR EACH ROW BEGIN  
DECLARE nb_bonne_reponse int;
DECLARE bonne_reponse varchar(255);
DECLARE valider int;
SET valider = 0;
SET nb_bonne_reponse = (select Bonne_reponse from question where Id=New.Id_question);

IF (nb_bonne_reponse = 1)THEN
    SET bonne_reponse = (select Reponse_1 from question where Id=New.Id_question);
    IF (bonne_reponse = New.reponse)THEN    
        UPDATE groupe SET Score = Score+1 where Id=New.Id_groupe);
    END IF;
ELSEIF (nb_bonne_reponse = 2)THEN
    SET bonne_reponse = (select Reponse_2 from question where Id=New.Id_question);
    IF (bonne_reponse = New.reponse)THEN    
        UPDATE groupe SET Score = Score+1 where Id=New.Id_groupe);
    END IF;
ELSEIF (nb_bonne_reponse = 3)THEN
    SET bonne_reponse = (select Reponse_3 from question where Id=New.Id_question);
    IF (bonne_reponse = New.reponse)THEN    
        UPDATE groupe SET Score = Score+1 where Id=New.Id_groupe);
    END IF;
ELSEIF (nb_bonne_reponse = 4)THEN
    SET bonne_reponse = (select Reponse_4 from question where Id=New.Id_question);
    IF (bonne_reponse = New.reponse)THEN    
        UPDATE groupe SET Score = Score+1 where Id=New.Id_groupe);
    END IF;
END|

mysql告诉我:

1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在

附近使用正确的语法
 '); 
 END IF;
 ELSEIF (nb_bonne_reponse = 2)THEN
 SET bonne_reponse = (' at line 13.

有人知道这里阻止了什么吗? 感谢

0 个答案:

没有答案