我写了以下代码
DELIMITER $$
CREATE TRIGGER bm_keuangan
AFTER UPDATE ON pembayaran_project FOR EACH ROW
BEGIN
DECLARE nama_project varchar(100);
DECLARE cek_di_keuangan varchar(100);
IF (!(isnull(NEW.deleted_at))) THEN
UPDATE keuangan SET keuangan.deleted_at = now() WHERE keuangan.ref = NEW.id AND keuangan.jk_id = 5;
ELSE
END IF;
END $$
DELIMITER ;
我得到了错误:
#1064-您的SQL语法有错误;查看与您的MariaDB服务器版本相对应的手册,以在'END IF附近使用正确的语法;
END',位于第10行
答案 0 :(得分:0)
您的ELSE块为空,这在mysql中是不允许的。您应该从代码中删除关键字ELSE,如下所示:
DELIMITER $$
CREATE TRIGGER bm_keuangan
AFTER UPDATE ON pembayaran_project FOR EACH ROW
BEGIN
DECLARE nama_project varchar(100);
DECLARE cek_di_keuangan varchar(100);
IF (!(isnull(NEW.deleted_at))) THEN
UPDATE keuangan SET keuangan.deleted_at = now() WHERE keuangan.ref = NEW.id AND keuangan.jk_id = 5;
END IF;
END $$
DELIMITER ;
答案 1 :(得分:0)
来自docs(重点是我):
IF search_condition THEN statement_list [ELSEIF search_condition THEN statement_list] ... [ELSE statement_list] END IF
每个
statement_list
包含一个或多个SQL语句; 不允许使用空的statement_list
。