Question
Using PL/SQL, create the exercises below Below is a function that will calculate the total discount based on an order ID. Using the code as
Using PL/SQL, create the exercises below
Below is a function that will calculate the total discount based on an order ID. Using the code as a starting template, modify it so that it will return the actual percentage of savings by also calculating the TotalCost and then dividing TotalDiscount by TotalCost to get the percent saved. ?You must calculate TotalCost in the same manner that TotalDiscount is being calculated below, e.g. use the Cursor and variables in the loop.
CREATE OR REPLACE FUNCTION getTotalDiscount
(o_id IN NUMBER)
return NUMBER
IS
TotalDiscount NUMBER := 0;
CURSOR getOrderItems IS
SELECT DISCOUNT_AMOUNT FROM order_items WHERE ORDER_ID = o_id;
BEGIN FOR items IN getOrderItems LOOP
TotalDiscount := TotalDiscount + items.DISCOUNT_AMOUNT;
END LOOP; RETURN TotalDiscount;
EXCEPTION WHEN OTHERS THEN
dbms_output.put_line('Something went wrong...');
END
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started