Results 1 to 3 of 3

Thread: Delete trigger

  1. #1
    Join Date
    May 2014
    Posts
    3

    Unanswered: Delete trigger

    Hello,

    i try to write a DELETE TRIGGER, but it doesn't going. Can anybody say to me why?
    Hier ist my Code:

    CREATE TRIGGER ord_delete Instead of DELETE On ord_view
    REFERENCING OLD AS alt
    FOR EACH ROW MODE DB2SQL
    BEGIN ATOMIC
    CASE WHEN alt.tid=1 THEN DELETE FROM ORD o Where o.id=1
    ELSE DELETE FROM ORD o Where o.id=alt.tid END
    END

    Thanks a lot

  2. #2
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    Hi,

    you're not allowed to use the CASE statement in a Compound SQL (inlined) statement.
    So, use one of the following:
    Code:
    CREATE TRIGGER ord_delete Instead of DELETE On ord_view
    REFERENCING OLD AS alt
    FOR EACH ROW MODE DB2SQL
    BEGIN
    CASE WHEN alt.tid=1 
      THEN 
         DELETE FROM ORD o Where o.id=1;
      ELSE 
         DELETE FROM ORD o Where o.id=alt.tid;
    END CASE;
    END
    or
    Code:
    CREATE or replace TRIGGER ord_delete 
    Instead of DELETE On ord_view
    REFERENCING OLD AS alt
    FOR EACH ROW
    BEGIN ATOMIC
    IF alt.tid=1
      THEN 
        DELETE FROM ORD o Where o.id=1;
      ELSE 
        DELETE FROM ORD o Where o.id=alt.tid;
    END IF;
    END
    Regards,
    Mark.

  3. #3
    Join Date
    May 2014
    Posts
    3
    That is it. Thank you very much

Tags for this Thread

Posting Permissions

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