RSS

7.3 Exception Scope

13 Apr

Lab Objectives

After completing this lab, you will be able to

  • Understand the scope of an exception

 

DECLARE

    v_student_id    NUMBER:= &sv_student_id;

    v_name  VARCHAR2(30);

    v_total NUMBER(1);

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);

   

    –inner block

    BEGIN

        SELECT COUNT(*)

            INTO v_total

            FROM enrollment

            WHERE student_id = v_student_id;

        DBMS_OUTPUT.PUT_LINE(‘Student is registered for ‘ || v_total || ‘ course(s)’);

    EXCEPTION –only be raised when error occurs in the inner block

        WHEN VALUE_ERROR OR INVALID_NUMBER THEN

            DBMS_OUTPUT.PUT_LINE(‘An error has occured’);

    END;

EXCEPTION –be global to the inner and outer block

    WHEN NO_DATA_FOUND THEN

        DBMS_OUTPUT.PUT_LINE(‘There is no such student’);

END;

Advertisements
 
Leave a comment

Posted by on 04/13/2010 in ORACLE

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: