O'Reilly logo

Oracle® PL/SQL® Interactive Workbook, Second Edition by Elena Silvestrova, Benjamin Rosenzweig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lab 10.1 Exception Scope

Lab Objectives

After this Lab, you will be able to:

Understand the Scope of an Exception

You are already familiar with the term scope—for example, the scope of a variable. Even though variables and exceptions serve different purposes, the same scope rules apply to them. Now examine the scope of an exception by means of an example.

FOR EXAMPLE

DECLARE 
   v_student_id NUMBER := &sv_student_id; 
   v_name VARCHAR2(30); 
BEGIN 
   SELECT RTRIM(first_name)||' '||RTRIM(last_name) 
     INTO v_name 
     FROM student 
    WHERE student_id = v_student_id; 

   DBMS_OUTPUT.PUT_LINE ('Student name is '||v_name); 
EXCEPTION 
   WHEN NO_DATA_FOUND THEN 
      DBMS_OUTPUT.PUT_LINE ('There is no such student'); 
END; 

In this example, you display the student’s name on the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required