Results 1 to 3 of 3

Thread: Trigger Error

  1. #1
    Join Date
    Aug 2010
    Posts
    21

    Unanswered: Trigger Error

    Hi . i want to create a trigger for display error when my product number equal 2

    Create trigger trg_4
    No cascade before insert on sales
    For each row mode db2sql
    when (select pro_num from product,sales where product.pro_id = sales.pro_id and product.pro_num= 2)
    Signal sqlstate '80000' ('Insufficient stock on hand!');

    in this trigger select statement exactly work but db2 return error for when
    why ???

  2. #2
    Join Date
    Dec 2005
    Posts
    273
    WHEN must be followed by a condition.

    e.g.

    when (( select COUNT(*) from product,sales where product.pro_id = sales.pro_id and product.pro_num= 2) < 2 )
    Signal sqlstate '80000' ('Insufficient stock on hand!');

    would work.

  3. #3
    Join Date
    Apr 2009
    Posts
    42
    you need to add "EXISTS" after "WHEN" statement.

Posting Permissions

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