-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram-11 Triggers.sql
More file actions
54 lines (34 loc) · 1.01 KB
/
Copy pathProgram-11 Triggers.sql
File metadata and controls
54 lines (34 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- Developer: <Aaron>
--
-- Program #: <Programming Assignment Number 11>
--
-- Description:
-- <Create a trigger,e product ID, total sales in dollars, and the total quantity sold for each product. >
-- Table Create
CREATE TABLE BB_SALES_SUM (
product_id VARCHAR2(30) PRIMARY KEY,
total_sales NUMBER(8,2),
total_qty NUMBER(10),
OrderPlaced number(1)
);
-- Trigger
CREATE OR REPLACE TRIGGER bb_salessum_trg
AFTER UPDATE OF orderplaced ON bb_basket
FOR EACH ROW
WHEN(OLD.orderplaced <> 1 AND NEW.orderplaced = 1)
BEGIN
UPDATE bb_sales_sum
SET total_qty = total_qty + :new.quantity
WHERE product_id = :new.idbasket;
END;
/
-- Test DATA
UPDATE bb_basket SET orderplaced = 1 WHERE idbasket = 14
UPDATE bb_basket SET orderplaced = 1 WHERE idbasket = 15
UPDATE bb_basket SET orderplaced = 1 WHERE idbasket = 16
-- Output
Table BB_SALES_SUM created.
Trigger BB_SALESSUM_TRG compiled
1 row updated.
1 row updated.
1 row updated.