An unexpected token "CREATE TRIGGER

那年仲夏 提交于 2019-12-17 05:15:14

问题


CREATE TRIGGER TRG_EFMREFNO 
   BEFORE 
   INSERT ON FEEDBACK_CASE_TB 
   FOR EACH ROW 
   BEGIN 
   SELECT SEQ_EFMREFNO.NEXTVAL INTO:NEW.EFMREFNO FROM DUAL;
   END;

please help me it's give errors

An unexpected token "CREATE TRIGGER TRG_EFMREFNO
BEFOR" was found following "BEGIN-OF-STATEMENT". Expected tokens may include: "<revoke>".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.12.79

An unexpected token "END-OF-STATEMENT" was found following "END". Expected tokens may include: "JOIN <joined_table>".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.12.79

Please give the solution for that errors


回答1:


You have 2 things going on here -

1) When the ";" character is part of the SQL statement, it's necessary to use a different character to terminate the statement. I typically use "@". To tell the "db2" command that you have chosen a different character, use

db2 -td@

or if you want to read from a file

db2 -td@ -f <somefile>

2) The correct way to update new row in a trigger is to set an alias for the new row, and use a set clause:

CREATE TRIGGER TRG_EFMREFNO 
   BEFORE 
   INSERT ON FEEDBACK_CASE_TB 
   REFERENCING NEW AS N
   FOR EACH ROW 
   BEGIN 
       SET N.EFMREFNO = SEQ_EFMREFNO.NEXTVAL;
   END
@

There may be other ways to use the sequence with the default clause in the create table statement that will accomplish the same thing:



来源:https://stackoverflow.com/questions/13266700/an-unexpected-token-create-trigger

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