for a typical products & shipping Database I am exploring the best way to run a trigger that:
- When an order line is set to 'Complete', a trigger is ran that:
- Looks for any other order lines for that order.
- If all other order lines for that order are also 'Complete'
- Update the order header table to complete.
For clatiry: The order header table would store the overall oder total, and the orderLines table stores each product of the order.
SO far, the trigger is written as such:
CREATE OR REPLACE TRIGGER orderComplete
after update ON orderline
for each row
WHEN (new.orderline_fulfilled = 'Y')
DECLARE count NUMBER := 5;
ordersNotDone NUMBER;
BEGIN
SELECT COUNT(Orderline_fulfilled) INTO ordersNotDone
FROM orderHeader
JOIN orderline ON
orderHeader.Order_id = orderLine.Orderline_order
WHERE Order_id = :old.orderline_order
AND orderline_fulfilled = 'Y';
IF ordersNotDone = 0
THEN
UPDATE orderHeader
SET completed = SYSDATE
WHERE orderId = :old.orderline_order;
ENDIF;
END;
This above causes the mutation error, when updating the orderline row.