An unexpected token "CREATE TRIGGER

后端 未结 1 2048
鱼传尺愫
鱼传尺愫 2020-11-27 23:48
CREATE TRIGGER TRG_EFMREFNO 
   BEFORE 
   INSERT ON FEEDBACK_CASE_TB 
   FOR EACH ROW 
   BEGIN 
   SELECT SEQ_EFMREFNO.NEXTVAL INTO:NEW.EFMREFNO FROM DUAL;
   END;         


        
相关标签:
1条回答
  • 2020-11-28 00:23

    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:

    0 讨论(0)
提交回复
热议问题