2. in Your Own Words, List the Benefits of Subprograms

2. in Your Own Words, List the Benefits of Subprograms

<p> Lab Assignment 8 CIS 208A PL/SQL Programming and SQL</p><p>Section 8-1, Exercise #2, 3, 4, 5, 6 </p><p>2. In your own words, list the benefits of subprograms.</p><p>3. In your own words, describe a stored procedure.</p><p>4. The remaining questions in this practice use a copy of the employees table. Create the copy by executing the following SQL statement: </p><p>CREATE TABLE employees_dup AS SELECT * from employees;</p><p>A. Use the code below to create a procedure in Application Express. Save the definition of your procedure in case you need to modify it later. In the “Save SQL” popup, name your saved work “My name change procedure.”</p><p>CREATE OR REPLACE PROCEDURE name_change IS BEGIN</p><p>UPDATE employees_dup SET first_name = 'Susan' WHERE department_id = 60; END name_change; </p><p>B. Execute the procedure by running the following anonymous block: </p><p>BEGIN name_change</p><p>END;</p><p>C. SELECT from the table to check that the procedure has executed correctly and performed the UPDATE:</p><p>Lab_8_Sp17_208A.doc 5. Create a second procedure named pay_raise which changes the salary of all employees in employees_dup to a new value of 30000. Execute the procedure from anonymous block, then SELECT from the table to check that procedure has executed correctly. </p><p>6. Retrieve your first name_change procedure by clicking on its name in the Saved SQL window. Modify the code to remove OR REPLACE from the CREATE statement, and introduce a deliberate error into the code, for example by misspelling a keyword: UPDAT employees_dup. Execute your code to recreate the procedure. What happens? </p><p>Section 8-2, Exercise #2, </p><p>2. Using the countries table: </p><p>A. Create a procedure that accepts a country_id as a parameter and displays the name of the country and its capitol city. Name your procedure get_country_info. Save your procedure definition for later use. </p><p>B. Execute your procedure from an anonymous block, using country_id 90. </p><p>C. Re-execute the procedure from the anonymous block, this time using country_id 95. What happens? </p><p>D. Retrieve your procedure code from Saved SQL and modify it to trap the NO_DATA_FOUND exception in an exception handler. Execute the modified procedure using country_id 95 again. Now what happens? </p><p>Section 8-3, Exercise #1, 2</p><p>1. Name the three modes for parameters and indicate which mode is the default mode. Which mode cannot be modified inside the procedure? </p><p>Lab_8_Sp17_208A.doc 2. Procedures: </p><p>A. Create a procedure that receives a country_id as an IN parameter and returns the name and population of that country as OUT parameters. Include an exception handler to trap the NO_DATA_FOUND exception if the country does not exist. The procedure should not display the returned values; this will be done in the next step. Name your procedure find_area_pop. Save your code. </p><p>B. Test your procedure by creating and executing an anonymous block that invokes the procedure and displays the returned OUT values. Save your code. Run the block twice, with country_ids 2 (Canada) and 10 (does not exist). </p><p>C. Retrieve your procedure code and modify it to add a third OUT parameter which is the population density of the country, using the formula: density = (population / area). You will need to modify your SELECT statement to fetch the area column value into a local variable. Save your modified code. </p><p>D. Test your modifed procedure using country_id 2. You will need to modify your calling anonymous block to declare and pass a fourth actual parameter to receive the population density from the procedure. Save your code. </p><p>Lab_8_Sp17_208A.doc</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    3 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us