且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL触发器定义-1064错误

更新时间:2022-12-01 10:21:10

您需要在过程中声明变量 msg并使用END IF

You need to declare your variable "msg" inside your procedure and use END IF

#START TRIGGER
delimiter //
CREATE TRIGGER passStandard_check BEFORE INSERT ON Module
FOR EACH ROW 
BEGIN 
    DECLARE msg VARCHAR(255); /* << PUT THIS HERE */
    IF NEW.passStandard < 0 || NEW.passStandard > 1 THEN 
        set msg = concat('Trigger Error: Pass Standard: ', cast(NEW.passStandard as char));
        signal sqlstate '45000' set message_text = msg;
    END IF; /* << YOU WILL NEED THIS TOO (DONT FORGET THE SEMICOLON :D) */
END//
delimiter ;
#END TRIGGER