Another commonly used statistic in reports is the total number of orders a shopp
ID: 3734646 • Letter: A
Question
Another commonly used statistic in reports is the total number of orders a shopper has placed. Follow these steps to create a function named NUM_PURCH_SF that accepts a shopper ID and returns a shopper's total number of orders. Use the function in a SELECT statement to display the number of orders for shopper 23.
1. Develop and run a CREATE FUNCTION statement to create the NUM_PURCH_SF function. The function code needs to tally the number of orders (using Oracle built-in function) by shopper. Keep in mind that the ORDERPLACED column contains a 1 if an order has been placed.
2. Create a SELECT query by using the NUM_PURCH_SF function on the IDSHOPPER column of the BB_SHOPPER table. Be sure to select only shopper 23.
Explanation / Answer
1.
create or replace function NUM_PURCH_SF(shopper_id number)
return number is num_orders number;
begin
select count(*) into num_orders from BB_SHOPPER where IDSHOPPER = shopper_id and ORDERPLACED = 1;
return num_orders;
end;
2.
select NUM_PURCH_SF(23) from dual;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.