<<compute_ratio>>
<<another_label>>
DECLARE
numerator NUMBER := 22;
denominator NUMBER := 7;
the_ratio NUMBER;
BEGIN
<<inner_label>>
<<another_label>>
DECLARE
denominator NUMBER := 0;
BEGIN
-- first use the denominator value = 7 from global DECLARE
-- to compute a rough value of pi
the_ratio := numerator/compute_ratio.denominator;
DBMS_OUTPUT.PUT_LINE('Ratio = ' || the_ratio);
-- now use the local denominator value = 0 to raise an exception
-- inner_label is not needed but used for clarification
the_ratio := numerator/inner_label.denominator;
DBMS_OUTPUT.PUT_LINE('Ratio = ' || the_ratio);
-- if you use a duplicate label, you might get errors
-- or unpredictable results
the_ratio := numerator/another_label.denominator;
DBMS_OUTPUT.PUT_LINE('Ratio = ' || the_ratio);
EXCEPTION
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE('Divide-by-zero error: can''t divide '
|| numerator || ' by ' || denominator);
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Unexpected error.');
END inner_label;
END compute_ratio;
/
PL/SQL Block Using Multiple and Duplicate Labels
0 comments:
Post a Comment