mysql触发器插入后插入错误

时间:2019-03-27 04:04:32

标签: mysql triggers

我在插入之前在触发器代码上有以下提示,但是当我尝试在终端上运行时,这给了我错误。


    DROP TRIGGER IF EXISTS `user_has_voice_queues_rt_Insert`;
DELIMITER $$
CREATE TRIGGER `user_has_voice_queues_rt_Insert` BEFORE INSERT ON `user_has_voice_queues_rt` 
FOR EACH ROW 
if(new.penalty=0) THEN 
    Set new.guard_name = (select IFNULL(max(penalty),'0') as max from user_has_voice_queues_rt where penalty between 0 and 6999) + 1;
Else If(new.penalty=1) THEN
    Set new.guard_name = (select IFNULL(max(penalty), '7000') as max from user_has_voice_queues_rt where penalty between 7000 and 8999) + 1;
Else IF(new.penalty=2) THEN
    Set new.guard_name = (select IFNULL(max(penalty),'9000') as max from user_has_voice_queues_rt where penalty between 9000 and 9500) + 1;
Else IF(new.penalty=3) THEN
    Set new.guard_name = (select IFNULL(max(penalty),'9500') as max from user_has_voice_queues_rt where penalty between 9501 and 9999) + 1;
END IF
$$
DELIMITER ;

enter image description here

1 个答案:

答案 0 :(得分:0)

全部替换

else if

使用

elseif