Display the output of the sql statement

Assignment Help PL-SQL Programming
Reference no: EM13499120

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.

Reference no: EM13499120

Questions Cloud

Explain what is the heat absorbtion for 100 g liquid water : What is the heat absorbtion for 100 g liquid water that is frozen to ice at 0 degrees C and 1 atm
Find the magnitude of the impulse delivered by the wall : A super ball, made of rubblerlike plastic, is thrown against a hard smooth wall. What is the magnitude of the impulse delivered by the wall
Explain the ratio of the number of atoms of the isotopes : The ratio of the number of atoms of the isotopes Ga-69 and Ga-71 in eight samples from different sources was measured in an effort to understand differences in reported values of the atomic mass of gallium.
What is the average angular speed of the grindstone : A grindstone of radius 4.0 m is initially spinning with an angular speed of 8.0 rad/s. What is the average angular speed of the Grindstone
Display the output of the sql statement : 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
Explain what is the millimolar mm concentration of ethanol : What is the millimolar (mM) concentration of ethanol in the blood at this limit. The density of ethanol is 0.789 g/ml.
Prepare the income statement and owner equity statement : Charles Brown opened Charlie's House Cleaners on March 1. During March, the following transactions were completed.
Estimate the torque on the loop : A semicircular loop lies in the z = 0 plane and carries a current I 50 A . When a magnetic flux density B = 2ay + az T is applied, what is the torque on the loop
Explain what are the major species present in solutions : What are the major species present in 0.250 M solutions of each of the following acids? Calculate the pH of each of these solutions.

Reviews

Write a Review

PL-SQL Programming Questions & Answers

  Create a database model

Create a database model and Submit the table creation statements for the Database Model.

  Write pl-sql procedures and functions

Write PL/SQL procedures and functions to populate and query that database

  Sql questions

Write a query to display using the employees table the EMPLOYEE_ID, FIRST_NAME, LAST_NAME and HIRE_DATE of every employee who was hired after to 1 January, 1995.

  Run the lab_03_01.sql script

Run the lab_03_01.sql script in the attached file to create the SAL_HISTORY table. Display the structure of the SAL_HISTORY table.

  Write sql queries

Write a query to display the last name, department number, and salary of any employee whose department number and salary both match the department number and salary of any employee who earns a commission.

  Explaining sql insert statement to insert new row in cds

Write down a SQL insert statement to insert new row in "CDS" table.

  Write down name of actors in ascending order

Write down actors (or actress, your choice, but not both) who have won at least two (2) Academy Awards for best actor/actress. Provide the actor name, movie title & year. Order the result by actor name."

  What is an sql injection attack

What is an SQL injection attack? Explain how it works, and what precautions must be taken to prevent SQL injection attacks.What are two advantages of encrypting data stored in the database?

  Determine resonant frequency in series rlc resonant circuit

Given the series RLC resonant circuit in the figure, operating at variable frequency, determine: The resonant frequency ω o ,  The circuit’s quality factor Q , The cut-off frequencies, f 1  & f 2  and the bandwidth BW

  Query that uses cube operator to return lineitemsum

Write summary query which uses CUBE operator to return LineItemSum (which is the sum of InvoiceLineItemAmount) group by Account(an alias for AccountDesciption).

  Query to show customers were missing for existing orders

As DBA, your manager called a meeting and asked why there are so many orders for customers that don't exist in the customer table. Write query which would shows which customers were missing for existing orders. Use a join or a subquery.

  Sql query into a relational algebra statement

Turn this SQL query into a relational algebra statement? SELECT Request.reqfor, Ordering.invamt, Ordering.invnbr, Ordering.invdat

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd