Neoview Guide to Stored Procedures in Java (R2.5)
}
}
Calling an SPJ in a Trigger
A trigger is a mechanism in the database that enables the database engine to perform certain
actions when a specified event occurs. SPJs are useful as triggered actions because they can help
you encapsulate and enforce rules in the database. For more information about the benefits of
using SPJs, see “Benefits of SPJs” (page 17).
Neoview SQL supports a CALL statement in a trigger provided that the SPJ in the CALL statement
does not have any OUT or INOUT parameters or return any result sets. For information about
OUT and INOUT parameters, see “Returning Output Values From the Java Method” (page 24)
and “Output Parameter Arguments” (page 53). For more information about result sets, see
“Returning Stored Procedure Result Sets” (page 25).
This example creates a trigger that executes an SPJ named LOWERPRICE when the
QTY_ON_HAND column of the PARTLOC table is updated and exceeds 500 parts:
CREATE TRIGGER sales.setsalesprice
AFTER UPDATE OF qty_on_hand
ON invent.partloc
FOR EACH STATEMENT
REFERENCING NEW as newqty
WHEN ( SUM(newqty.qty_on_hand) > 500 )
CALL sales.lowerprice();
For information about the CREATE TRIGGER syntax, see the Neoview SQL Reference Manual.
Calling an SPJ in a Trigger 59