运行时:
DELIMITER $$
CREATE TRIGGER tr_test BEFORE UPDATE ON test
FOR EACH ROW
BEGIN
DECLARE EXIT HANDLER FOR SQLSTATE '45000';
DECLARE EXIT HANDLER FOR SQLSTATE '23000';
IF(older_record(NEW.last_action_timestamp, OLD.last_action_timestamp)) THEN
SET @rowhash = (SELECT MD5(NEW));
INSERT INTO test_db.test_table SELECT NEW.*, @rowhash;
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'old record';
END IF
END
$$
DELIMITER ;
我收到以下错误消息:
您的SQL语法有错误;查看与您的> MariaDB服务器版本对应的手册,以便在&#39 ;;附近使用正确的语法; DECSTARE EXIT HANDLER for SQLSTATE' 23000&#39 ;; IF(old_record(NEW.l'第4行
)
答案 0 :(得分:1)
DECLARE
语句后面必须跟一个"语句" - 见https://dev.mysql.com/doc/refman/5.6/en/declare-handler.html
也许你想要的只是
BEGIN END;
显然是一个空洞的陈述"是不允许的?