Create a script file containing the pl/sql code

Assignment Help PL-SQL Programming
Reference no: EM13802814

The purpose of this lab is to work with basic PL/SQL syntax to create an anonymous block of code. In the lab, you will be using SQL*Plus to modify one of the tables in the MovieRental schema and then write a simple block of code to update the table with some new data and then execute the code in SQL*Plus. As an additional task in the lab, you will be asked to modify the existing PL/SQL block of code given to you to add exception handling and then execute it in SQL*Plus. Both of these concepts will help enforce the material covered in this second week.

For the lab, you will need to create a script file containing the PL/SQL code that will address the lab steps below. Run the script file in your SQL*Plus session using the SET ECHO ON session command at the beginning to capture both the PL/SQL block code and output from Oracle after the block of code has executed. To successfully test the code in Step 3, you will need to copy/paste your code into SQL*Plus for each movie ID as you change the value for the host variable. Spool your output to a file named with your last name plus lab 2 and give the file a text (.txt) extension. For example, if your last name was Johnson then the file would be named johnson_lab2.txt. Submit both the spooled output AND the script file for grading of the lab.

Step 1:

As business is becoming strong and the movie stock is growing for More Movie Rentals, the manager wants to do more inventory evaluations. One item of interest concerns any movie for which the company is holding $75 or more in value. The manager wants to focus on these movies in regards to their revenue generation to ensure the stock level is warranted. To make these stock queries more efficient, the application team decides that a column should be added to the MM_MOVIE table named STK_FLAG that will hold a value '*' if stock is $75 or more. Otherwise, the value should be NULL. Add the new column to the MM_MOVIE table as a CHAR data type.

Execute a DESC MM_MOVIE on the table both before you add the new column and after the column is added.

Step 2:

Create an anonymous block of PL/SQL code that contains a CURSOR FOR loop to accomplish the task described above in Step 1. Your loop will need to interrogate the value (using an IF statement) found in the movie_qty field of the cursor loop variable to see if it is >= 75. If this is true then you will need to update the new column in the table with an '*' WHERE CURRENT OF the table. If the quantity is not >= 75 (the ELSE side of the IF statement) then update the new column with a NULL.
Execute a SELECT * from MM_MOVIE both before and after you execute the new PL/SQL block of code to show that the process works.

Step 3:

Here is a block that retrieves the movie title and rental count based on a movie ID provided via a host variable.

SET SERVEROUTPUT ON
VARIABLE g_movie_id NUMBER

BEGIN

:g_movie_id := 4;

END;

/
DECLARE

v_count NUMBER;

v_title mm_movie.movie_title%TYPE;

BEGIN

SELECT m.movie_title, COUNT(r.rental_id)

INTO v_title, v_count

FROM mm_movie m, mm_rental r

WHERE m.movie_id = r.movie_id

AND m.movie_id = :g_movie_id

GROUP BY m.movie_title;
DBMS_OUTPUT.PUT_LINE(v_title || ': ' || v_count);

END;

/
Modify the block of code to add exception handlers for errors that you can and cannot anticipate. You will need to execute the entire code listing shown above each time you wish to test it by changing the value of :g_movie_id for each test.
Once finished, test your exception handling by running the modified block for the following values of :g_movie_id. Be sure that you can capture the value in the :g_movie_id host variable.
12 - normal output will display title and number of rentals
13 - exception - there is no movie ID for 13
1 - exception - Movie with ID 1 has never been rented.

Reference no: EM13802814

Questions Cloud

Who is audrey hepburn and what did she do : Who is Audrey Hepburn? what did she do? What does her quote The beauty of a woman is not in a facial mode but the true beauty in a woman is reflected in her soul.
What is the relationship between legal and ethical issues : How might these issues be relevant to organizational and personal decisions? What is the relationship between legal and ethical issues?
Decreases as output increases-vertically integrated firm : Which of the following always decreases as output increases? The Southern Tree Trimming Corporation reported an accounting profit of $35,000 and a normal rate of return of 15 percent on capital and enterprise of $30,000. The opportunity cost of labor..
Summarize the results of your self-assessment of cultural : The assignment: (1-2 pages) Summarize the results of your self-assessment of cultural intelligence. Explain how and why your cultural intelligence might influence your ability to lead in a setting that is highly diverse. Be specific and use examples ..
Create a script file containing the pl/sql code : For the lab, you will need to create a script file containing the PL/SQL code that will address the lab steps below. Run the script file in your SQL*Plus session using the SET ECHO ON session command at the beginning to capture both the PL/SQL blo..
What role does the usa play in globalization : What role does the USA play in globalization?
He five with the mean listed first and the standard deviatio : Need help with 95% confidence interval. Have 5 that need to be figured out. The five with the Mean listed first and the standard deviation next are as follows: Mean: 20,330.5; SD: 53,510.2 Mean: 5.417; SD: 4.336 Mean: 2.000 SD: 3.684 Mean: 1.637 SD: ..
Make the most accurate diagnosis possible from info : Instructions: For each of the following case studies, play the role of a clinician and make the most accurate diagnosis possible from the given information (Clinical Axis I disorders only - NO Personality Disorders). Your answer may be just a few wor..
Implementing improvements in its supply chain : A comparison of two computer manufacturers found that by implementing improvements in its supply chain, one company was able to reduce its average supply of key components to only 3-6 days’ supply of inventory, as compared with their competitor, whic..

Reviews

Write a Review

PL-SQL Programming Questions & Answers

  The database design

Update the TOC to reflect the new section.Name the document CS251_ _Final.doc.Submit the document for grading.Submit your database file to the Submission Area.

  Data processing of an international based organization

Imagine that you have been hired as a consultant to assist in streamlining the data processing of an international based organization that sells high-end electronics. The organization has various departments such as payroll, human resources, finan..

  Write sql to correction create the beach table

Write SQL to correction create the BEACH table, Write SQL to inset the data into the BEACH table

  Shows the shipping and billing addresses

Create a view named CustomerAddresses that shows the shipping and billing addresses for each customer in the MyGuitarShop database.

  Create a pl-sql block using the hr schema

Create a PL/SQL block to achieve the following using the HR schema and select the name, salary, and department of the employee with the maximum salary.

  Draw an entity-relationship diagram

Draw an Entity-Relationship Diagram (ERD) for the data storage requirements of a business described in the case study and Data Model Transformation.

  Part 1you are to write a 6 - 7page paper in the apa format

part 1you are to write a 6 - 7page paper in the apa format about a topic related to this course turn in the final copy

  Create sql statements for the scenarios

Create SQL statements for the scenarios. Your response should include SQL statement, output and any other assumptions you have made to arrive at the solution.

  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.

  Write a query to display the starting salary

Write a query to display the starting salary for each employee. The starting salary would be the entry in the salary history with the oldest salary start date for each employee. Sort the output by employee number.

  Write a sql statement to return some columns

Prepare this SQL query and sort the result set by CategoryName and then by ProductName in ascending order- Write a SQL statement to return some columns

  Write an update statement that modifies the row

Write an UPDATE statement that modifies the row you just added to the Categories table. This statement should change the ProductName column to "Woodwinds", and it should use the CategoryID column to identify the row.

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