CREATE TRIGGER expiryset ON test FOR INSERT
BEGIN
DECLARE exp TIMESTAMP;
DECLARE name TEXT;
SET @name := (SELECT name from test ORDER BY created_at DESC limit 1);
SET @exp := (SELECT TIMESTAMPADD(WEEK,2,(CURRENT_TIMESTAMP)));
UPDATE test SET expiry = @exp WHERE name= @name;
END;
上述触发器有效,但只有在执行时我无法保存。语法错误
答案 0 :(得分:0)
您必须将DELIMITER
设置为与默认;
不同的内容,才能将整个代码整理在一起。
DELIMITER $$
CREATE TRIGGER expiryset AFTER INSERT ON test FOR EACH ROW
BEGIN
DECLARE exp TIMESTAMP;
DECLARE name TEXT;
SET @name := (SELECT name from test ORDER BY created_at DESC limit 1);
SET @exp := (SELECT TIMESTAMPADD(WEEK,2,(CURRENT_TIMESTAMP)));
UPDATE test SET expiry = @exp WHERE name= @name;
END$$
DELIMITER ;