Vous êtes sur la page 1sur 2

ECS 165A Database Systems Madhavi Gandhi

Winter 2003 Feb 21, 2003

Assignment 4 SQL and PL/SQL Programming


Due: Tue. March 4th, Homework box (by 2pm) In this assignment, you have to work with the database auctiondb. Using same steps from the second assignment, download or wget auctiondb2.sql. In sqlplus use command @auctiondb2.sql to create same tables with new data you need to use for this assignment. We use the following relation schemas for auctiondb: MEMBERS(MID, PASSWORD, MNAME, ADDR, PHONE, EMAIL) ITEMS(INO, CATEGORY, TITLE, IDESC, SELLERID MEMBERS, STARTPRICE, BID INCREMENT, LASTBID, CLOSETIME) BID(BUYERID MEMBERS, INO ITEMS, BIDTIME, PRICE) SHIPPING(INO ITEMS, SHIPTYPE, SHIPPRICE) RATING(INO ITEMS, USERID MEMBERS, UCOMMENT, USCALE) In this assignment you have to program some PL/SQL functions and procedures. Make sure that you read section 4 of the Oracle/SQL tutorial that describes how to program in PL/SQL. Please also take a look at any notes from the discussion sections. Problem 1: PL/SQL Function Write following PL/SQL function (see tutorial section 4.1.6) shipfunct that takes INO and SHIPTYPE as input and outputs shipping price of the item. For SHIPTYPE U (ups shipping) shipping price is 10% of the items sale price. For SHIPTYPE P (post oce shipping) shipping price is 2% of the items sale price. Your function shipfunct should output an appropriate message (e.g. as part of an exception) if the item number does not exist in the database or SHIPTYPE is invalid (or other than U or P). Otherwise, the function shipfunct returns a positive value which is interpreted as the shipping price for the given item with given shipping type option. Use your function to compute the answers to following questions: a. What is the shippring price for item Title for: 106 if shipped UPS? b. What is the shippring price for item Title for: 222 if shipped using post oce? (10 Points)

You have to submit the commented PL/SQL source code for your function . Make sure that your PL/SQL programs include appropriate error handling routines. You also have to submit the result sets computed by the function as detailed in questions above. Problem 2: PL/SQL Procedure (15 Points) You now have to write a PL/SQL procedure named shiptablell that takes as input, a parameter stating the type of items you are to consider (open - O, closed - C, both - B) and utilizes the function shipfunct programmed in problem 1. The procedure populates the SHIPPING table for items of type given as input (closed (C), open (O) or both (B)) assuming that every item with item number divisible by 5 uses ups shipping type (U) and all the other items are shipped by post oce shipping type (P). e.g. items with INO = 100, 105 were shipped using ups shipping type and INO = 1, 106 were shipped using post oce shipping type. First your procedure has to verify the validity of the input (C, O or B) and has to output a respective message in case the parameter is not valid. Then the procedure nds appropriate items for which tuples in the SHIPPING table have to be output (dbms output package). For each valid item based on the input, shipping type is determined by the procedure and corresponding ship price is calculated. Item number, ship type and ship price are recorded in the SHIPPING table. Note that open items have closetime greater than sysdate and closed items have closetime less than or equal to sysdate. You have to submit the commented PL/SQL source code for your procedure. Make sure that your PL/SQL program includes appropriate error handling routines. Problem 3: PL/SQL procedure and SQL queries (15 Points)

a. Use shiptablell(C) to create the shipping table with information about closed items. b. Report number of tuples created, total number of items using each ship type (ups, post oce) and total cost of shipping of all items of each ship type. c. Use shiptablell(O) to create the shipping table with information about open items. d. Report number of tuples created, total number of items using each ship type (ups, post oce) and total cost of shipping of all items of each ship type. e. Delete all tuples from SHIPPING table. Use shiptablell(B) to create the shipping table with information about all items. f. Report number of tuples created, total number of items using each ship type (ups, post oce) and total cost of shipping of all items of each ship type.