我是mysql的新手,我正在尝试为我正在处理的应用程序做一个相对简单的触发器,但我担心我似乎无法找到错误的位置,就像我的老师并不是真的很有帮助...希望你们能帮助我......这是代码:
CREATE OR REPLACE
TRIGGER TR_NUEVOMECA AFTER INSERT ON MECADISTRIBUIDOS FOR EACH ROW
DECLARE
VARIABLEBUCLE NUMBER;
MESACTUAL NUMBER;
BEGIN
SET MESACTUAL=(SELECT EXTRACT(MONTH FROM NOW()));
IF (NEW.TIPOASC == 1) THEN
SET VARIABLEBUCLE = 12;
ELSIF (NEW.TIPOASC == 2) THEN
SET VARIABLEBUCLE = 6;
ELSIF(NEW.TIPOASC == 3) THEN
SET VARIABLEBUCLE = 4;
ELSIF(NEW.TIPOASC == 4) THEN
SET VARIABLEBUCLE = 3;
ELSIF(NEW.TIPOASC == 6) THEN
SET VARIABLEBUCLE = 2;
ELSIF(:NEW.TIPOASC == 12) THEN
SET VARIABLEBUCLE = 1;
END IF;
WHILE(VARIABLEBUCLE>0) DO
INSERT INTO MANTENIMIENTOS VALUES(0,:NEW.IDENTIF,NULL,NULL,NULL,MESACTUAL);
SET VARIABLEBUCLE=VARIABLEBUCLE - 1;
SET MESACTUAL=MESACTUAL + NEW.TIPOASC;
IF(MESACTUAL>12) THEN
SET MESACTUAL=MESACTUAL%12;
END IF;
END WHILE;
END;
这是日志照片: enter image description here 先谢谢你们。