RSS

7.4.1 Use User-Defined Exceptions

16 Apr

DECLARE

    v_instructor_id NUMBER:= &sv_instructor_id;

    v_tot_sections  NUMBER;

    v_name  VARCHAR2(30);

    e_too_many_sections EXCEPTION;

BEGIN

    SELECT COUNT(*)

        INTO v_tot_sections

        FROM section

        WHERE instructor_id = v_instructor_id;

       

    IF v_tot_sections >= 10 THEN

        RAISE e_too_many_sections;

    ELSE

        SELECT RTRIM(first_name) ||   || RTRIM(last_name)

            INTO v_name

            FROM instructor

            WHERE instructor_id = v_instructor_id;

        DBMS_OUTPUT.PUT_LINE(‘Instructor, ‘ || v_name || ‘, teachers ‘ || v_tot_sections || ‘ sections’);

    END IF;

EXCEPTION

    WHEN e_too_many_sections THEN

        DBMS_OUTPUT.PUT_LINE(‘This instructor teaches too much’);

END;

Advertisements
 
Leave a comment

Posted by on 04/16/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: