Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions