如何解决DB2错误“在“ BEGIN-OF-STATEMENT”之后发现意外的令牌CREATE或REPLACE TRIGGER,

时间:2018-12-28 06:18:43

标签: sql triggers db2

我正在尝试创建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触发器出了什么问题。

1 个答案:

答案 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@