I have to create a user-defined function that executes a simple sql query
I have to create a user-defined function that executes a simple sql query
but it’s not working. I can create the function but I can’t figure out how to call it up with the proper input parameters (the zip code). Don’t know if it matters but the class is using Oracle SQL and not MySQL. Any help would be greatly appreciated.
Develop a PL/SQL user-defined function ZIP_CODE_SALES that returns the total sales for a zip code when the zip code is supplied as an input parameter. You may use any of your zip codes you wish. Show the PL/SQL statements in your function, the execution of your function, and the results returned.
create or replace function “ZIP_CODE_SALES” (p_zip DISTRIBUTORS.ZIP%type)
return float
is
v_sales number;
begin
select sum(S.GROSS_SALE_PRICE) into v_sales
from DISTRIBUTORS D, SALES S, SALEPERSONS SP, ORDER_SHIPMENTS OS
where S.SALESPERSON_ID = SP.SALESPERSON_ID and
OS.DEALER_ID = SP.DEALER_ID and
OS.DIST_ID = D.DIST_ID;
return v_sales;
end;
/
FUNCTION ZIP_CODE_SALES compiled
select ZIP_CODE_SALES(‘34711’) from dual;