Assignment 2
Due date: |
07 October 2014 |
Value: |
100% |
|
|
Please submit the CODE and OUTPUT for all programming questions.
For the output, a screen dump is highly encouraged.
IMPORTANT NOTES – PLEASE READ BEFORE YOU BEGIN WORK
In this assignment, you will use the CAR HIRE database. The CAR HIRE database including appropriate data will be made available on the USQ Oracle server. You can query these tables as if they are in your own schema but you are not permitted to insert or update data in these tables. The specification for the CAR HIRE database is as follows:
The table descriptions appear below, including the column names, datatypes and the meanings for values in the columns. Familiarise yourself with the tables and the data.
I_CAR
I_CARGROUP
I_MODEL
I_CUSTOMER
I_BOOKING
Question 1 (35 marks)
Write a function (called most_recent_rental) that returns the most recent date of rental for a particular car (registration) for all completed bookings made for that car. If a rental does not exist for that car registration, the function should return ‘NO RENTALS’ (5 marks)
Write a second function (called maximum_rental_period) that returns the maximum rental period for a particular car (registration) for all completed bookings made for that car. If the car has only one booking but has not been returned it should return a ‘-999’ for the rental period. (5 Marks)
For both the functions, you should check for completed bookings, i.e. miles_in is not null.
Write a procedure that takes a car registration and returns the most recent date of rental and the maximum rental period for that car. The procedure had the following formal parameters (10 Marks)
PROCEDURE CAR_DETAIL( REGISTRATION IN VARCHAR2, RECENT_DATE VARCHAR2, RENTAL_PERIOD OUT NUMBER)
Write an anonymous block to call the procedure using an explicit cursor to display the details (registration, most_recent_rental, maximum_rental_period) for all the cars in the i_car table by calling the procedure above. The output should only include cars that have a booking and have been returned. (10 Marks)
The CAR_REGSTRATION was last rented on MOST_RECENT_RENTAL and has had the longest rental period of MAXIMUM_RENTAL_PERIOD.
Write ONE SQL statement that displays the registration, model name and cost for each car and calls the two functions to display the most recent date of rental and the maximum rental period for each of the cars. (5 marks)
Display the output of the SQL statement.
Question 2 (20 marks)
The car hire company is concerned about possible unauthorised changes to customer details that may compromise the company’s security and privacy policies. You will create a database trigger to monitor such changes to some important columns in the I_CUSTOMER table.
CREATE TABLE CUSTOMER_CHANGELOG
(
cust_no NUMBER(5),
cust_name VARCHAR2(20),
contact VARCHAR2(20),
log_date DATE);
UPDATE MY_CUSTOMER
SET cust_name=”Sam Spade”, contact=”Kaptain Krunch”
WHERE cust_no = 8981;
Question 3 (40 marks)
Create a PL/SQL procedure called report_rental_month which has the needed IN parameters for year and month. The procedure will display to the screen the following format for each car rented during that year/month in the i_booking table. The information needs to be retrieved using an explicit cursor for all rentals in that year for that month.
Car REGISTRATION was rented TIMES for a total of DAYS
You will need to write extra functions to calculate the number of times and total number of days the car was booked for that month for that year to be called from within the procedure. Again only where the rental has finished and the car has been returned.
Write a procedure called report_booking_totals that will produce the following output in the format specified bellow. The procedure needs to use explicit cursor/s for each year starting with the oldest year produces a summary of the cars rented for that month. The years and month output needs to be in ascending order.
Year 2011
January
Car REGISTRATION was rented TIMES for a total of DAYS
Car REGISTRATION was rented TIMES for a total of DAYS
March
Car REGISTRATION was rented TIMES for a total of DAYS
Car REGISTRATION was rented TIMES for a total of DAYS
Year 2012
February
Car REGISTRATION was rented TIMES for a total of DAYS
July
Car REGISTRATION was rented TIMES for a total of DAYS
Total number of booking is COUNT for a total of DAYS with income of $AMOUNT.XX.
Currently there are COUNT numbers of rentals not finalized
The AMOUNT is to be calculated with a function call. Rentals not finalized are rentals that have not been returned to the rental place. The numbers not finalized is to be calculated either with a function call or during the processing of the procedure.
Important Notes:
MARKING CRITERIA
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more