RSS

8.2.1 Use User-defined Exceptions

29 Apr

SET SERVEROUTPUT ON

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;

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

INTO v_name

FROM instructor

WHERE instructor_id = v_instructor_id;

IF v_tot_sections >= 10 THEN

RAISE e_too_many_sections;

ELSE

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

END IF;

EXCEPTION

WHEN e_too_many_sections THEN

DBMS_OUTPUT.PUT_LINE(‘Instructor, ‘ || v_name || ‘, teaches too much’);

END;

Advertisements
 
Leave a comment

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