Results 1 to 4 of 4

Thread: Trigger Syntax

  1. #1
    Join Date
    Apr 2016
    Posts
    10

    Answered: Trigger Syntax

    Hello,
    i am new to db2 and migrating some oracle DB objects into DB2.
    I am trying to migrate an quite easy oracle trigger into DB2 but I don´t get the problem.
    The Orace Syntax ist the following:

    Code:
    CREATE OR REPLACE TRIGGER ATTACHMENT_INSERT
    BEFORE INSERT ON ATTACHMENT FOR EACH ROW
    BEGIN
      SELECT ATTACHMENT_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;
    END;
    Can anyone support me with the correct db2 equivalent?

  2. Best Answer
    Posted by mark.b

    "Hello,

    Try this:
    Code:
    CREATE OR REPLACE TRIGGER ATTACHMENT_INSERT
    BEFORE INSERT ON ATTACHMENT 
    REFERENCING NEW AS N
    FOR EACH ROW
    SET N.ID=ATTACHMENT_SEQ.NEXTVAL
    "


  3. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    What DB2 version and OS are you using? For those of us who do not know Oracle, what is the trigger supposed to do?

    Andy

  4. #3
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    Hello,

    Try this:
    Code:
    CREATE OR REPLACE TRIGGER ATTACHMENT_INSERT
    BEFORE INSERT ON ATTACHMENT 
    REFERENCING NEW AS N
    FOR EACH ROW
    SET N.ID=ATTACHMENT_SEQ.NEXTVAL
    Regards,
    Mark.

  5. #4
    Join Date
    Apr 2016
    Posts
    10
    Quote Originally Posted by ARWinner View Post
    What DB2 version and OS are you using? For those of us who do not know Oracle, what is the trigger supposed to do?

    Andy
    Sorry Andy you are right that was not very clever. I was talking about an Linux Express-C 10.5 Environment. That Trigger should create an id before insert of a new row in the table.

    The SQL from the last post is working properly. Thanks for that!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •