我正在尝试创建db2触发器,以便在单独的表中维护事务历史记录。但是我遇到了错误,无法继续。
SQL错误[42601]:意外令牌“ CREATE TRIGGER HISTORY_TRIGGER 在“ BEGIN-OF-STATEMENT”之后找到“ AFTER”。预期的令牌可能 包括:“”。SQLCODE = -104,SQLSTATE = 42601,DRIVER = 4.22.29
我正在通过dbeaver执行sql。
我已经尝试过An unexpected token "CREATE TRIGGER,但没有帮助。
CREATE TRIGGER HISTORY_TRIGGER AFTER INSERT OR UPDATE ON MY_SCHEMA.TRANSACTIONS_TABLE
REFERENCING OLD ROW AS OLD
NEW ROW AS NEW
BEGIN
INSERT INTO MY_SCHEMA.HISTORY_TABLE
(ID, EMAIL, REASON, ROLE, TIMESTAMP)
VALUES(NEW.ID, NEW.EMAIL, NEW.REASON, NEW.ROLE, CURRENT_TIMESTAMP);
END
请帮助我找出我的SQL触发器出了什么问题。
答案 0 :(得分:2)
Window-> Preferences-> General-> Editors-> SQL Editor-> SQL Processing-> Statement Delimiter:@
CREATE OR REPLACE TRIGGER HISTORY_TRIGGER
AFTER INSERT OR UPDATE ON MY_SCHEMA.TRANSACTIONS_TABLE
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
BEGIN
INSERT INTO MY_SCHEMA.HISTORY_TABLE (ID, EMAIL, REASON, ROLE, TIMESTAMP)
VALUES(NEW.ID, NEW.EMAIL, NEW.REASON, NEW.ROLE, CURRENT_TIMESTAMP);
END@