I want to insert a row into an ITEM table if certain SKUs are inserted.
There are two triggers where each looks for a particular SKU and inserts the
appropriate matching row in the same table. However when a record is
inserted, the following error message occurs:
Under DB2 UDB v7.2
[IBM][CLI Driver][DB2/NT] SQL0101N The statement is too long or too
complex. LINE NUMBER=2. SQLSTATE=54001
Under DB2 UDB v8.1
[IBM][CLI Driver][DB2/NT] SQL0723N An error occurred in a triggered SQL
statement in trigger "DBA.ITEM_B". Information returned for the error
includes SQLCODE "-101", SQLSTATE "54001" and message tokens "".
SQLSTATE=09000
Both messages point to a recursion of triggers. This seems to be confirmed
by dropping either of the two triggers. The trouble is the condition for
the triggers should never happen. I've provided sample SQL statements below
to recreate the situation. Why is this happening? Thanks in advance.
CREATE TABLE ITEM (
ORDER_NO CHARACTER(10) NOT NULL,
SKU_NO CHARACTER(10) NOT NULL,
UNITS INTEGER NOT NULL
)
;
CREATE TRIGGER ITEM_A AFTER INSERT ON ITEM REFERENCING NEW AS N_ROW FOR EACH
ROW MODE DB2SQL WHEN
(
n_row.sku_no = 'A1'
)
begin atomic
INSERT INTO ITEM
(ORDER_NO, SKU_NO, UNITS)
VALUES (N_ROW.ORDER_NO, 'A2', 1);
end
CREATE TRIGGER ITEM_B AFTER INSERT ON ITEM REFERENCING NEW AS N_ROW FOR EACH
ROW MODE DB2SQL WHEN
(
n_row.sku_no = 'B1'
)
begin atomic
INSERT INTO ITEM
(ORDER_NO, SKU_NO, UNITS)
VALUES (N_ROW.ORDER_NO, 'B2', 1);
end
INSERT INTO ITEM
(ORDER_NO, SKU_NO, UNITS)
VALUES
('100', 'C1', 1);