This Study Resource Was: Assignment - Stored Procedure and UDF
This Study Resource Was: Assignment - Stored Procedure and UDF
SQL SCRIPT 1: Create a stored procedure SHOWSTATE() that has a parameter of two-character state
code ( eg. NY, CA, NJ) that will list all information about the customer who lives on a particular state.
Refer CUSTOMER table. The state code can be in lower or uppercase supplied in the parameter. Use CA
to test your stored procedure.
--#SET TERMINATOR @
BEGIN
m
er as
BEGIN
co
eH w
DECLARE a1 CURSOR WITH RETURN FOR
o.
SELECT * FROM CUSTOMER
rs e
ou urc
WHERE ADDRESS LIKE ('%' || Customer ||'%');
OPEN a1;
o
aC s
END;
vi y re
END @
--#SET TERMINATOR ;
ed d
ar stu
Call SHOWSTATE('CA')
is
Th
sh
This study source was downloaded by 100000829178195 from CourseHero.com on 11-22-2021 01:44:17 GMT -06:00
https://www.coursehero.com/file/61592036/Stored-Procedure-and-UDFpdf/
m
er as
co
eH w
o.
Hint: Use LIKE and UPPER in your stored procedure.
rs e
ou urc
SQL SCRIPT 2: Formulate a stored procedure DISPLAYTRANS() that will display the corresponding sales
transaction based from transaction number passed. Display transaction number, sales date, product
code, description, unit, quantity. Use TR000039 to test the output of your script.
o
--#SET TERMINATOR @
aC s
vi y re
BEGIN
ar stu
BEGIN
is
FROM sales s
This study source was downloaded by 100000829178195 from CourseHero.com on 11-22-2021 01:44:17 GMT -06:00
https://www.coursehero.com/file/61592036/Stored-Procedure-and-UDFpdf/
WHERE transNum = sd.transNo;
OPEN a1;
END;
END @
--#SET TERMINATOR ;
CALL DISPLAYTRANS('TR000039')
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
SQL SCRIPT 3: Create a user-defined function GET_TOTAL_PAYMENT() that will get the total payment
made for each transaction. A transaction number parameter will be included when the function is
called. Use TR000092 to test your function.
is
Th
--#SET TERMINATOR @
RETURNS DOUBLE
NO EXTERNAL ACTION
BEGIN ATOMIC
This study source was downloaded by 100000829178195 from CourseHero.com on 11-22-2021 01:44:17 GMT -06:00
https://www.coursehero.com/file/61592036/Stored-Procedure-and-UDFpdf/
DECLARE total_payment DOUBLE;
FROM PAYMENT
GROUP BY 1);
RETURN total_payment;
END@
m
er as
--#SET TERMINATOR ;
co
eH w
SELECT DISTINCT GET_TOTAL_PAYMENT('TR000092') "TOTAL PAYMENT"
o.
FROM payment
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
SQL SCRIPT 4: Create a stored procedure PAYMENT_SHORT that will display the transaction number,
customer name, total sales, total payment, and the difference between total sales and total payment.
This stored procedure has no parameters.
sh
On this procedure you will use different sets of view that you have created to extract to total sales
depending on the correct unit price to be used based on effectivity date and sales date.
Create these views first before using it inside your stored procedure.NO NEED TO DISPLAY THE
CONTENT OF THESE VIEWS.
This study source was downloaded by 100000829178195 from CourseHero.com on 11-22-2021 01:44:17 GMT -06:00
https://www.coursehero.com/file/61592036/Stored-Procedure-and-UDFpdf/
To display output of the requirement, include GET_TOTAL_PAYMENT user-defined function that you
have created in item 3. TRANSNO should serve as the parameter AND NOT TR000092.
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh
This study source was downloaded by 100000829178195 from CourseHero.com on 11-22-2021 01:44:17 GMT -06:00
https://www.coursehero.com/file/61592036/Stored-Procedure-and-UDFpdf/
Powered by TCPDF (www.tcpdf.org)