我正在尝试在MySQL中构建一个触发器,该触发器将在将新行插入表中后运行。 如果检测到错误,那么我想将该触发器写入表。否则,我不想将错误写入表。我想尝试避免添加无限的空行。
这是我的代码:
CREATE
TRIGGER character_validation4 AFTER INSERT
ON address FOR EACH ROW
Begin
IF(New.city REGEXP '^[^a-zA-Z0-9]')
THEN
INSERT INTO errorlog (city, mainprocessid) Values("There is an error with the city", New.ID));
END
但我发现最后一个支架上有错误。
有人可以帮忙吗?感谢
答案 0 :(得分:2)
DELIMITER \\
CREATE
TRIGGER character_validation4 AFTER INSERT
ON address FOR EACH ROW
Begin
IF(New.city REGEXP '^[^a-zA-Z0-9]')
THEN
INSERT INTO errorlog (city, mainprocessid) Values("There is an error with the city", New.ID);
END IF;
END \\
DELIMITER ;
答案 1 :(得分:1)
看来你在New.ID之后有一个额外的“)”。试试这种方式
CREATE TRIGGER character_validation4
AFTER INSERT ON address FOR EACH ROW Begin
IF(New.city REGEXP '^[^a-zA-Z0-9]') THEN INSERT INTO errorlog (city, mainprocessid)
Values("There is an error with the city", New.ID);
END IF;
END;