Question: Assignment 9-7: Updating Summary Data Tables. The Brewbean's owner uses several summary sales data tables every day to monitor business activity. The BB_SALES_SUM table holds
Assignment 9-7: Updating Summary Data Tables.
The Brewbean's owner uses several summary sales data tables every day to monitor business activity. The BB_SALES_SUM table holds the product ID, total sales in dollars, and total quantity sold for each product. A trigger is needed so that every time an order is confirmed or the ORDERPLACED column is updated to 1, the BB_SALES_SUM table is updated accordingly. Create a trigger named BB_SALESUM_TRG that perform this task. Before testing, reset the ORDERPLACED column to 0 for basket 3, as shown in the following code, and use this basket to test the trigger.
This is what I have so far, am i on the right path?
CREATE OR REPLACE TRIGGER bb_salesum_trg AFTER UPDATE OF orderplaced ON bb_basket FOR EACH ROW WHEN (NEW.orderplaced = 1) DECLARE CURSOR basketitem_cur IS SELECT idproduct, quantity, price, option1 FROM bb_basketitem WHERE idbasket = :NEW.idbasket; lv_sale_num NUMBER(5,2) := 0; lv_qty_num NUMBER(3,1) := 0; BEGIN FOR basketitem_rec IN basketitem_cur LOOP lv_sale_num := basketitem_rec.price * basketitem_rec quantity; IF basketitem_rec.option1 = 1 THEN lv_qty_num := (.5 * basketitem_rec.quantity); ELSE lv_qty_num := basketitem_rec.quantity; END IF; UPDATE bb_sales_sum SET tot_sales = nvl(tot_qty,0) + lv_qty_num, tot_qty = nvl(tot_qty,0) + lv_qty_num WHERE idproduct = basketitem_rec.idproduct; END LOOP; END;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
