Scope rules - user-defined exceptions, PL-SQL Programming

Scope Rules

You cannot declare an exception twice in the similar block. Though, you can, declare the similar exception in 2 different blocks. The Exceptions declared in a block are considered local to that block and global to all its sub-blocks. As a block can reference only local or global exceptions, enclosing the blocks cannot reference the exceptions declared in the sub-block. If you re-declare a global exception in a sub-block, the local declarations prevail. Therefore, the sub-block cannot reference the global exception unless it was declared in the labeled block, in that situation the syntax below is valid:

block_label.exception_name

The illustration below describes the scope rules:

DECLARE

past_due EXCEPTION;

acct_num NUMBER;

BEGIN

DECLARE ---------- sub-block begins

past_due EXCEPTION; -- this declaration prevails

acct_num NUMBER;

BEGIN

...

IF ... THEN

RAISE past_due; -- this is not handled

END IF;

END; ------------- sub-block ends

EXCEPTION

WHEN past_due THEN -- does not handle RAISEd exception

...

END;

The enclosed blocks do not handle the raised exception as the declarations of past_due in the sub-block prevail. Though they share the similar name, the two past_due exceptions are unlike, just as the two acct_num variables share the similar name but are various variables. Hence, the RAISE statement and WHEN clause refer to various exception. To have the enclosing block handle the raised exception, you should remove its declaration from the sub-block or define the OTHERS handler.

Posted Date: 10/5/2012 5:12:42 AM | Location : United States







Related Discussions:- Scope rules - user-defined exceptions, Assignment Help, Ask Question on Scope rules - user-defined exceptions, Get Answer, Expert's Help, Scope rules - user-defined exceptions Discussions

Write discussion on Scope rules - user-defined exceptions
Your posts are moderated
Related Questions
Left and Right Joins LEFT OUTER JOIN can be used when you want to retrieve the data from the main table (table1) even if there is no match in other tables (table_2, table_3...

Identifiers You use identifiers to name the PL/SQL program items and units that include constants, variables, cursors, exceptions, cursor variables, subprograms, and packages.

Inserting Objects: You can use the INSERT statement to add objects to an object table. In the illustration below, you insert a Person object into the object table persons:

Data Types in SQL - Character CHARACTER or, synonymously, CHAR, for character strings. When this type is to be the declared type of something (e.g., a column), the permissible

CHECK Constraints in SQL A CHECK constraint is a table constraint defined using the key word CHECK, as already illustrated in several examples in this chapter. In particular,

Many of the reports generated from the system calculate the total dollars in purchases for a shopper. Complete the following steps to create a function named TOT_PURCH_SF that acce

NULL Statement The NULL statement clearly specifies in action; it does nothing other than to pass control to the next statement. It can, though, improve the readability. In a

Datatype Conversion At times it is necessary to convert a value from one datatype to another. For e.g. if you want to inspect a rowid, you should convert it to a character stri

Updating Tables in SQL The topic of updating by describing the assignment operator, ":=" in Tutorial D. SQL uses a different syntax for assignment, using the key word SET and

Using Operator REF: You can retrieve refs by using the operator REF that, like VALUE, takes as its argument a correlation variable. In the illustration below, you retrieve one