100% found this document useful (1 vote)
352 views3 pages

Database Programming With PL/SQL 7-4: Practice Activities

This document discusses scope of exceptions in PL/SQL. It provides definitions for key terms like exception propagation, visibility of exceptions, and scope of exceptions. It includes sample code to demonstrate how moving exception handlers and declarations in and out of inner and outer blocks affects exception handling. When the exception handler is moved out of the inner block, the exception is no longer caught. When the exception declaration is moved out of the inner block to the outer block, the exception can now be caught in the outer handler.

Uploaded by

liliana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
352 views3 pages

Database Programming With PL/SQL 7-4: Practice Activities

This document discusses scope of exceptions in PL/SQL. It provides definitions for key terms like exception propagation, visibility of exceptions, and scope of exceptions. It includes sample code to demonstrate how moving exception handlers and declarations in and out of inner and outer blocks affects exception handling. When the exception handler is moved out of the inner block, the exception is no longer caught. When the exception declaration is moved out of the inner block to the outer block, the exception can now be caught in the outer handler.

Uploaded by

liliana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

www.oracle.

com/academy

Database Programming with PL/SQL


7-4: Recognizing the Scope of Exceptions
Practice Activities Vocabulary
Identify the vocabulary word for each definition below:

The inner block terminates unsuccessfully, and PL/SQL passes


Propagacion de
the exception to the outer block.
excepciones

The portion of the program where the exception can be


Visibilidad de
accessed without using a qualifier.
excepciones

The portion of a program in which the exception is declared and


AMBITO DE
is accessible.
EXCEPCIONES

Try It / Solve It
1. Enter and run the following code twice, once for each of the two country_ids, 5
(which does not exist) and 672 (Antarctica, which does exist but has no currency).

DECLARE v_country_name countries.country_name%TYPE;


v_currency_code
countries.currency_code%TYPE;
BEGIN DECLARE e_no_currency
EXCEPTION;
BEGIN
SELECT country_name, currency_code INTO v_country_name, v_currency_code
FROM countries
WHERE country_id = 5; -- repeat with 672
IF v_currency_code = 'NONE' THEN
RAISE e_no_currency;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('This country does not exist');
WHEN e_no_currency THEN
DBMS_OUTPUT.PUT_LINE('This country exists but has no currency');
END;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Another type of error occurred'); END;
2

A. Explain the output. Save your code.

El id 5, aparece el mensaje de que no existe el país y con el id 672 se muestra un mensaje de que el país existe
pero la moneda no.

B. Modify the code to move the two exception handlers to the outer block. Leave the
declaration of e_no_currency in the inner block. Execute twice, again using
country_ids 5 and 672. Now what happens and why? Save your code.

DECLARE
v_pais_nom
countries.country_name%TYPE;
v_currency
countries.currency_code%TYPE;
BEGIN
DECLARE
e_no_currency EXCEPTION;
BEGIN
SELECT country_name, currency_code
INTO v_pais_nom, v_currency
FROM countries
WHERE country_id = 5;
IF v_currency = 'NONE' THEN
RAISE e_no_currency;
END IF; END;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE(‘el pais no existe’ );
WHEN e_no_currency THEN
DBMS_OUTPUT.PUT_LINE(‘Este país existe pero no tiene moneda’);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(‘otro tipo de error ocurrio’);
END;
C. Modify the code again to move the declaration of e_no_currency to the outer block.
Execute the code again using country_ids 5 and 672. Now what happens and why?

DECLARE v_pais_nom
countries.country_name%TYPE;
v_currency
countries.currency_code%TYPE;
e_no_currency EXCEPTION;
BEGIN
SELECT country_name, currency_code
INTO v_pais_nom, v_currency
FROM countries
WHERE country_id = 5;
IF v_currency = 'NONE' THEN
RAISE e_no_currency;
END IF; END;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE(‘el pais no existe’ );
WHEN e_no_currency THEN
DBMS_OUTPUT.PUT_LINE(‘Este país existe pero no tiene moneda’);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(‘otro tipo de error ocurrio’);
END;

You might also like