Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask PL-SQL Expert

Question 1

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'

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.

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

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.

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.

Display the output of the SQL statement.

Question 2

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.

1. Create a copy of the I_CUSTOMER table in your own schema by using the following command:
CREATE TABLE MY_CUSTOMER AS SELECT * FROM I_CUSTOMER;

2. Also create a table to store change logs (CUSTOMER_CHANGELOG) by using the following command:

CREATE TABLE CUSTOMER_CHANGELOG

(

cust_no NUMBER(5),

cust_name VARCHAR2(20),

contact VARCHAR2(20),

log_date DATE);

3. Create a database trigger with the following specification:

  • fires AFTER an UPDATE on MY_CUSTOMER table.
  • fires if there is any change to cust_name or contact columns of the MY_CUSTOMER table.
  • fires for each row.
  • inserts a first row: the affected cust_no column, the OLD values of the cust_name and contact columns and the current date into the table CUSTOMER_CHANGELOG.
  • inserts a second row: the affected cust_no column, the NEW values of the cust_name and contact columns and the current date into the table CUSTOMER_CHANGELOG.

4.      Test the trigger with the following specification:

  • Go ahead and make a change to MY_CUSTOMER table by issuing the following command:

UPDATE MY_CUSTOMER

SET cust_name = 'Sam Spade', contact = 'Kaptain Krunch'

WHERE cust_no = 8981;

5. Now, select all rows from the CUSTOMER_CHANGELOG table. This should display the old and new values of the changes you made due to firing of the trigger. Output all the rows of CUSTOMER_CHANGELOG table.

Question 3

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:

  • You must NOT use any implicit cursors, table joins, subqueries, set operators, group functions or SQL functions (such as COUNT) to create the PL/SQL function or the PL/SQL anonymous block.
  • The PL/SQL anonymous block must be ONE block only. Do NOT write a block to perform each task of the specification above.

PL-SQL, Programming

  • Category:- PL-SQL
  • Reference No.:- M91036240
  • Price:- $70

Priced at Now at $70, Verified Solution

Have any Question?


Related Questions in PL-SQL

Purpose of the assessment with ulo mapping the purpose of

Purpose of the assessment (with ULO Mapping) The purpose of this assignment is to develop skills in managing data in databases and to gain understanding of data model development and implementation using a commercially a ...

Complete the following tasksin microsoft access create the

Complete the following tasks: In Microsoft Access, create the database and tables that you identified in W3 Assignment 2. In Microsoft Word, write the SQL statements to create the database and tables. Write SQL statement ...

Assignment - queries functions and triggersaimthe aims of

Assignment - Queries, Functions and Triggers Aim The aims of this assignment are to: formulate SQL queries; populate an RDBMS with a real dataset, and analyse the data; design test data for testing SQL queries; create SQ ...

For this assignment you will be provided a database backup

For this assignment, you will be provided a database backup for a database called FinanceDB. You will have to restore this backup to your own version of SQL Server. All of the questions in this assignment relate to the F ...

Continuing the project you have worked on in weeks 1-4 in

Continuing the project you have worked on in Weeks 1-4, in this final week, complete the following tasks: Refine your database and SQL statements by incorporating your instructor's feedback. Verify that the database comp ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As