0

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 12

delimiter |
CREATE TRIGGER `pointhistorytrigger` AFTER UPDATE ON `points`
 FOR EACH ROW BEGIN
 IF NEW.is_open='4'
 THEN
  INSERT into point_history (`idpoints`,`idmembers`,`action_time`,`action_type`)
  VALUES (OLD.idpoints,NEW.idmembers,NOW(),'3');
ELSE IF NEW.is_open='3'
 THEN
  INSERT into point_history (`idpoints`,`idmembers`,`action_time`,`action_type`)
  VALUES (OLD.idpoints,NEW.idmembers,NOW(),'2');
 END IF;
END;
| delimiter ;
4

3 回答 3

1
delimiter |
CREATE TRIGGER `pointhistorytrigger` 
AFTER UPDATE ON `points`
FOR EACH ROW 
BEGIN
    IF NEW.is_open='4' THEN
        INSERT into point_history (`idpoints`,`idmembers`,`action_time`,`action_type`)
        VALUES (OLD.idpoints,NEW.idmembers,NOW(),'3');
    ELSEIF NEW.is_open='3' THEN
        INSERT into point_history (`idpoints`,`idmembers`,`action_time`,`action_type`)
        VALUES (OLD.idpoints,NEW.idmembers,NOW(),'2');
    END IF;
END |   -- <<== remove the semi colon here
delimiter ;
于 2013-04-30T12:15:38.590 回答
0

If you are using an else-if in MySQL you have to use ELSEIF instead of ELSE IF. Everything else is fine in your statement.

于 2013-04-30T12:19:30.160 回答
0

You need 2 end if , one for if and another for else if...So your final trigger will be like this..

DELIMITER |
CREATE TRIGGER `pointhistorytrigger` AFTER UPDATE ON `points` FOR EACH ROW
BEGIN
 IF NEW.is_open='4' THEN
  INSERT into point_history (`idpoints`,`idmembers`,`action_time`,`action_type`)  VALUES (OLD.idpoints,NEW.idmembers,NOW(),'3');
 ELSE IF NEW.is_open='3' THEN
  INSERT into point_history (`idpoints`,`idmembers`,`action_time`,`action_type`)  VALUES (OLD.idpoints,NEW.idmembers,NOW(),'2');
 END IF;
END IF;
END;
于 2016-04-08T12:45:32.410 回答