插入之前的DB2触发器

时间:2018-10-13 14:42:30

标签: db2 database-trigger

插入前的DB2触发器无法删除表中的行

CREATE TRIGGER WDW.user_name_search_del
before INSERT ON WDW.user_name_search_b
REFERENCING NEW AS new
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
Delete from wdw.user_name_search_b
where user_name = new.user_name ;--

它抛出错误

  

在“名称= new.user_name”之后发现意外的标记“ END-OF-STATEMENT”。预期的令牌可能包括:“” .. SQLCODE = -104,SQLSTATE = 42601,DRIVER = 4.9.78 SQL代码:-104,SQL状态:42601

1 个答案:

答案 0 :(得分:0)

要修复的两件事:

  1. 将“ BEGIN ATOMIC”更改为“ BEGIN”。 “ BEGIN ATOMIC”块中不支持DELETE
  2. 在“;-”之前添加“; END”以结束“ BEGIN”块。

声明应为:

CREATE TRIGGER WDW.user_name_search_del 
  before INSERT ON WDW.user_name_search_b 
  REFERENCING NEW AS new 
  FOR EACH ROW 
  MODE DB2SQL 
BEGIN  
  Delete 
  from wdw.user_name_search_b 
  where user_name = new.user_name; 
END;