PL/SQL Exceptions  «Prev  Next»

Handling Predefined Server Exceptions-Exercise

Handling predefined Server Exceptions

Objective: Modify the SQL to add exception handlers.

Exercise Scoring

This exercise is worth a total of 25 points. You'll receive up to 20 points for adding exception handlers to the PL/SQL block. You will receiveup to 5 points for justifying the reasons for the exception handlers that you selected to add.
  • Background and Overview
    In a previous module, you used the following code to learn about cursors:
    DECLARE
    
    v_prod_id NUMBER;
    
      CURSOR get_product is SELECT product_id FROM 
    PRODUCT WHERE 
    
    product_name = 'Rabbit';
    
    BEGIN
      
    OPEN get_product;
    
      FETCH get_product INTO v_prod_id;
    
      INSERT INTO PET_CARE_LOG (product_id, log_datetime, 
    log_text) 
    
      VALUES (v_prod_id, 
    
            TO_DATE('12-DEC-99 05:30PM','DD-MON-YY 
    HH:MIPM'), 
      
      'Rabbits eat fresh grass only.');
    
      CLOSE get_product;
    
      COMMIT;
    
    END;
    
    In this exercise, you need to add two exception handlers to this code.
  • Instructions
    1. Download the SQL for the above code to your local machine.
    2. Add the exception handlers to the file.
    3. Justify your reasons for the exception handlers that you selected to add.
  • Download Please download the exercise1.sql that lists the code for the PL/SQL block.
  • Submitting your exercise Once you have written your PL/SQL block, place it within the text area below and click the Submit button.