Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxxviii Special Issue On Database And Expert Systems Applications Lncs 11250

Authors: Abdelkader Hameurlain ,Roland Wagner ,Sven Hartmann ,Hui Ma

1st Edition

3662583836, 978-3662583838

More Books

Students also viewed these Databases questions

Question

At what level(s) was this OD intervention scoped?

Answered: 1 week ago