Ask Computer Engineering Expert

Your first procedure is to be named MOVIE_RENTAL_SP and is going to provide functionality to process movie rentals. Based on data that will represent the movie id, member id and payment method your procedure will need to generate a rental id and then insert a new row of data into the mm_rental table. The process will also need to update the quantity column in the mm_movie table to reflect that there is one less copy of the rented movie in stock. Along with the processing you will also need to define some user-defined exception handlers that will be used in validating the input data. Since you may need to recreate your procedure several times during the debugging process it is suggested that you use the CREATE OR REPLACE syntax at the beginning of the CREATE statement.

The following steps will help you in setting up your code.

You will need to define three parameters, one each for movie id, member id, and payment method. Make sure that each one matches the data type of the associated column in the database tables. 
You will have several other variables that will need to be identified and defined. It might be easier to read through the rest of the specs before you start trying to define these (look for hints in the specifications. 
You will need to define four user-defined exceptions; one for unknown movies, one for unknown member, one for unknown payment method, and one for if a movie is unavailable. 
You will need to validate each of the three pieces of data passed to the procedure. One easy way to do this might be to use a SELECT statement with the COUNT function to return a value into a variable based on a match in the database table against the piece of data that you are validating. If the query returns a zero then there is no match and the data is invalid; any value greater than zero means a match was found and thus the data is valid. You will need the following validations. 
Validate the movie id to make sure it is valid. If not then raise the unknown movie exception. 
Validate the member id to make sure one exists for that id. If not then raise the unknown member exception. 
Validate the payment method to make sure it exists. If not then raise the unknown payment method exception. 
Check the movie quantity to make sure that there is a movie to be rented for the movie id. If not then raise the unavailable movie exception.
If all the data passes validation then you will need to create a new rental id. This process should be in a nested block with its own EXCEPTION section to catch a NO_DATA_FOUND exception if one should happen. You can generate a new rental id by find the largest rental id value in the mm_rental table (Hint: MAX function) and then increasing that value by one. The NO_DATA_FOUND exception would only be raised if there were no rental id's in the table. 
Now you are ready to insert a new row of data into the mm_rental table. Use the SYSDATE function for the check out date and NULL for the check in date. 
Now update the mm_movie table to reflect one less movie for the associated movie id. 
Finally you will need to set up an EXCEPTION section for all of your exception handling. For each exception output you want to state what the problem is, the invalid data value and a note that the rental cannot proceed. For example, for an invalid movie id number you might say "There is no movie with id: 13 - Cannot proceed with rental". You also want to include a WHEN OTHERS exception handler. 
Compile and check your code. If you get a PROCEDURE CREATED WITH COMPILATION ERRORS message then type in SHOW ERRORS and look in your code for the line noted in the error messages (be sure to compile your code with the session command SET ECHO ON). Once you have a clean compile then your are ready to test.

Step 2: Testing the first procedure



You will need to test for scenarios that will allow both a clean movie rental and test each exception. This means that you will need to run at least 5 test cases. One each for the following:

No movie for the id supplied (use 13, 10, and 2 for the parameters). 
No member for the id supplied (use 10, 20, and 2 for the parameters). 
No payment method for the id supplied (use 10, 10 and 7 for the parameters). 
A successful rental (use 5, 10 and 2 for the parameters). 
No movie available for the id supplied (use 5, 11, and 2 for the parameters). Since there is only one movie available for id 5 you will get this exception.
You output from the testing should look similar to (this would be the output for the first test above):

exec movie_rent_sp(13, 10, 2);
Output:
There is no movie with id: 13 
Cannot proceed with rental 
PL/SQL procedure successfully completed.

Be sure that when you have verified that everything works you run your testing in a spools session and save the file to be turned in.

Step 3: Creating the second procedure



Your second procedure should be named MOVIE_RETURN_SP and should facilitate the process of checking a movie rental back in. For this procedure you will only need to pass one piece of data to the procedure; the rental id. You will need two user-defined exceptions; one for no rental record and one for already returned. You will be able to use several of the same techniques you used in the first procedure for your validation.

The following steps will help in setting up your code.

You will need to define only one parameter for the rental id number. Make sure that it matches the data type of the associated column in the database table. 
You will have several other variables that will need to be identified and defined. It might be easier to read through the rest of the specs before you start trying to define these (look for hints in the specifications). 
You will need to define the two user-defined exceptions mentioned above. 
You will need to validate the rental id that is passed to the procedure. If it is not a valid one then raise the associated exception. 
If it is valid then get the movie id and check in date from the mm_rental table. 
Now check the check in date to make sure that it is NULL. If it is not then raise the associated exception. 
If everything checks out then update the mm_rental table for the rental id you have and use the SYSDATE function for the check in date. 
Now you can update the quantity in the mm_movie table for the associated movie id to reflect that the movie is back in stock. 
Last, set up your exception section using appropriate error message text and data.
Compile and check your code. If you get a PROCEDURE CREATED WITH COMPILATION ERRORS message then type in SHOW ERRORS and look in your code for the line noted in the error messages (be sure to compile your code with the session command SET ECHO ON). Once you have a clean compile then your are ready to test.

Step 4: Testing the second procedure




You will need to test for scenarios that will allow both a clean rental return and test each exception. This means that you will need to run at least 3 test cases. One each for the following:

No rental for the id supplied (use 20 for the parameter). 
A successful rental return (use 1 for the parameter). 
Try to return the same rental in step 2.
You output from the testing should look similar to (this would be the output for the first test above):

exec movie_return_sp(20);
Output:
There is no rental record with id: 20 
Cannot proceed with return 
PL/SQL procedure successfully completed.

Be sure that when you have verified that everything works you run your testing in a spools session and save the file to be turned in.

Step 5: Creating the function




Your function should be named MOVIE_STOCK_SF and will be used to return a message telling the user whether a movie title is available or not based on the movie id passed to the function. The exception handling that will be needed is for NO_DATA_FOUND but we are going to set it up as a RAISE_APPLICATION_ERROR.

The following steps will help in setting up your code.

You will need to define only one parameter for the movie id number. Make sure that it matches the data type of the associated column in the database table. Also, since you will be returning a notification message you will want to make sure your RETURN statement references a data type that can handle that (Hint: variable length data type). 
You will have several other variables that will need to be identified and defined. It might be easier to read through the rest of the specs before you start trying to define these (look for hints in the specifications). 
You will not be doing any validation so the first thing you need to do is retrieve the movie title and quantity available from the mm_movie table based on the id passed to the function. 
Now you need to determine if any are available. IF the value in the quantity column is greater than zero then you will be returning a message saying something like "Star Wars is available: 0 on the shelf", ELSE if the value is zero then you should return a message saying something like "Star Wars is currently not available". Hint: A good way to return a test string is to assign it to a variable and then simply use the variable name in the RETURN clause. 
Finally, set up your exception section to use a RAISE_APPLICATION_ERROR for the NO_DATA_FOUND exception handler. Assign an error number of -20001 to it and an error message that states there is no movie available for the id (be sure to include the id in the message).
Compile and check your code. If you get a FUNCTION CREATED WITH COMPILATION ERRORS message then type in SHOW ERRORS and look in your code for the line noted in the error messages (be sure to compile your code with the session command SET ECHO ON). Once you have a clean compile then your are ready to test.

Step 6: Testing the function 



You will need to test for all three possible scenarios. 

Test for a movie in stock using movie id 11. 
Test for a movie not in stock using movie id 5 (from your tests of the second procedure above the quantity should be 0). 
Test for an invalid movie id using movie id 20.
For test number 2 you may need to manipulate the quantity amount in the database which will be fine.

Test your function by using a select statement against the DUAL table like in the example below:

select movie_stock_sf(20) from dual; 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9650898

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 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