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

  Write select statement to return those rows with due balance

Write SELECT statement which returns those rows with the balance due greater than 1000. Sort result set by InvoiceTotal, with largest invoice first.

  You have been asked to design a data model

Law Associates is a large legal practice based in Sydney. You have been asked to design a data model for the practice based upon the following specification

  Create a ssis package to implement incremental processing

A view must be created to allow DigitalX employees to view all the products on backorder and the quantity of each on order. Your view must aggregate the data from the backorder products so that each product appears only once in the list.

  Using the oracle developer data modeler tool

Credit will be given to queries that are not trivial, for example, "SELECT * FROM Tablename" is unlikely to gain more than one mark. SQL Developer can be used to produce the queries and populate the tables.

  Design database for school students

Design a database to maintain information about school staff and students satisfying following properties: 1. Staff will be having their id, name and classes they are teaching 2. Student will be having name, roll no,..

  Submit the table creation statements for the database model

submit the table creation statements for the database model. submit them all in a single script file.also submit a

  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.

  Point totals by race level listing

List the Rider's Name, RaceLevel as Race_Level and the total number of all points based on their placement. Make sure that you don't list any riders who have not raced in any races yet (not placed yet).

  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?

  Find the sum of the elements of a

A is an ArrayList of size N. The elements of A are integers, they are in sorted order increasing from the low end of the array, and no two integers are the same. Variable x is an integer. Which of the following operations takes time that is less t..

  Display customers table and its fields in sql

Display all the LastNames from the Customers table and any associated OrdersIDs from the Orders Table. Show the LastName even if they do not have any associated orders. Order the results by LastName in ascending order.

  Describe an algorithm you could use that would output each

Given a list containing Province, CustomerName and SalesValue (sorted by Province and CustomerName), describe an algorithm you could use that would output each CustomerName and SalesValue with the total SalesValue per Province.

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