2

请帮我找出触发器语句中的错误。

CREATE TRIGGER textmain_insert BEFORE INSERT ON textmain
FOR EACH ROW 
BEGIN
    IF NEW.text_create_datetime = '0000-00-00 00:00:00' THEN
        SET NEW.text_create_datetime = NOW();
    END IF
    IF NEW.text_update_datetime = '0000-00-00 00:00:00' THEN
        SET NEW.text_update_datetime = NOW();
    END IF
END;
4

1 回答 1

1
  • 更改delimiter
  • 每次后终止end if

尝试,

DELIMITER $$
CREATE TRIGGER textmain_insert BEFORE INSERT ON textmain
FOR EACH ROW 
BEGIN
    IF NEW.text_create_datetime = '0000-00-00 00:00:00' THEN
        SET NEW.text_create_datetime = NOW();
    END IF;
    IF NEW.text_update_datetime = '0000-00-00 00:00:00' THEN
        SET NEW.text_update_datetime = NOW();
    END IF;
END $$
DELIMITER ;
于 2012-09-19T03:10:20.383 回答