DB2 trigger illegal token

点点圈 提交于 2019-12-11 14:42:55

问题


Fairly new to DB2 sql, so forgive my ignorance :) I have a trigger with a condition inside. I want to then insert some params depending on the condition.. Here it is:

I've looked at DB2 documentation for triggers and also for if statements, and at least to my eyes it appears to comply with it, however i get a -104 error (Illegal symbol token) on the insert line.

The insert works fine provided i use values not from 'N'.

OK, it works if i have nothing in the if then statement.. but only if i have nothing!

Thanks


回答1:


My guess would be that DB2 is confused by your statement terminators. You use a semicolon to terminate the CREATE TRIGGER statement, but at the same time you use the same terminator inside the CREATE TRIGGER statement, after the INSERT.

In whatever client you use to execute your code, redefine the statement terminator to something else and place that terminator at the end of CREATE TRIGGER, after END ID. For example, if you use the command line processor, save this to a file trig.sql:

 CREATE OR REPLACE TRIGGER AUTO_INSERT_DEPO_NOMINEE
  AFTER INSERT ON CA_ENTITLEMENT 
  REFERENCING NEW AS N
  FOR EACH ROW

  IF  NOT EXISTS (SELECT D.DEPO_CD FROM DEPO D WHERE D.DEPO_CD = N.DEPO_CD)
  THEN    
    INSERT INTO DEPO (DEPO_CD, DEPO_NME, BRANCH_CD, AUTO_GENERATED) 
           VALUES(N.DEPO_CD, NULL, N.BRANCH_CD, 'Y');
  END IF@

then run it, specifying "@" as the statement terminator:

db2 -td@ -f mytrig.sql


来源:https://stackoverflow.com/questions/21750346/db2-trigger-illegal-token

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!