我写了下面的代码

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附近使用正确的语法;
  
  在第10行结束

最佳答案

您的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 ;

关于mysql - 为什么触发器上的“其他”被认为是错误的?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53986950/

10-10 11:23