id="summaryscope">Summary of 'name' scoping in nested compound statements

As stated earlier, nested compound statements can be used within an SQL routine to define the scope of SQL variable declarations, cursors, condition names, and condition handlers. Additionally, labels have a defined scope in the context of nested compound statements. However the rules for name space, and how non-unique names can be referenced, differs depending on the type of name. The following table summarizes these differences.

Table 76. Summary of 'Name' Scoping in Nested Compound Statements
Type of name Must be unique within... Qualification allowed? Can be referenced within...
SQL variable the compound statement in which it is declared, excluding any declarations in compound statements that are nested within that compound statement. Yes, can be qualified with the label of the compound statement in which the variable was declared. the compound statement in which it is declared, including any compound statements that are nested within that compound statement. When multiple SQL variables are defined with the same name you can use a label to explicitly refer to a specific variable that is not the most local in scope.
condition the compound statement in which it is declared, excluding any declarations in compound statements that are nested within that compound statement. No the compound statement in which it is declared, including any compound statements that are nested within that compound statement. Can be used in the declaration of a condition handler, or in a SIGNAL or RESIGNAL statement.

When multiple conditions are defined with the same name there is no way to explicitly refer to the condition that is not the most local in scope.

cursor the compound statement in which it is declared, excluding any declarations in compound statements that are nested within that compound statement. No the compound statement in which it is declared, including any compound statements that are nested within that compound statement.

When multiple cursors are defined with the same name there is no way to explicitly refer to the cursor that is not the most local in scope. However, if the cursor is defined as a result set cursor (i.e., the WITH RETURN clause was specified as part of the cursor declaration), the invoking application can access the result set.

label the compound statement that declared the variable, including any declarations in compound statements that are nested within that compound statement. No the compound statement in which it is declared, including any compound statements that are nested within that compound statement.

Use a label to qualify the name of an SQL variable or as the target of a GOTO, LEAVE, or ITERATE statement.



[ Top of Page | Previous Page | Next Page | Contents |
Index ]