The target label must be in the same scope as the GOTO statement

A GOTO statement's target label must be in the same scope as the GOTO statement. In the context of the GOTO statement, each of the following constructs maintains its own scope:

· Functions

· Procedures

· Anonymous blocks

· IF statements

· LOOP statements

· Exception handlers

· CASE statements

The following code examples show common programming errors. Each illustrates an attempt to branch to a label that is out of scope, and each generates the following PL/SQL error:

PLS-00375: illegal GOTO statement; this GOTO cannot branch to label

IF conditions

The only way to enter an IF statement is through an evaluation of an IF condition to TRUE. Therefore, this code produces an error:

GOTO label_inside_IF;IF status = 'NEW'THEN <<label_inside_IF>> /* Out of scope! */ show_new_one;END IF;

Likewise, you can't jump into the middle of a CASE statement.

BEGIN statements

The only way to enter a block-within-a-block is through the sub-block's BEGIN statement. PL/SQL insists on orderly entrances and exits. This code produces an error because it doesn't comply with this structure:

GOTO label_inside_subblock;BEGIN <<label_inside_subblock>> /* Crosses block boundary! */ NULL;END;

Scope of IF statements

Each IF clause of the IF statement is its own scope. A GOTO may not transfer from one clause to another. This code produces an error:

IF status = 'NEW'THEN <<new_status>> GOTO old_status; /* Crosses IF clause boundary! */ELSIF status = 'OLD'THEN <<old_status>> GOTO new_status; /* Crosses IF clause boundary! */END IF;

Likewise, you can't jump from one clause to another within a CASE statement.

Don't jump into the middle of a loop

You cannot jump into the middle of aloop with a GOTO. This code produces an error:

FOR month_num IN 1 .. 12LOOP <<do_a_month>> schedule_activity (month_num);END LOOP;GOTO do_a_month; /* Can't go back into loop. */

Don't GOTO a local module

You cannot issue a GOTO from the main body of a block to a label in a function, procedure, or other module defined within that block. This code produces an error:

DECLARE FUNCTION local_null IS BEGIN <<descrip_case_statement>> NULL; END;BEGIN GOTO descrip_case_statement; /* Label not visible here. */END;

4.3.1.3 The target label must be in the same part of the PL/SQL block as the GOTO

The target label must be in the same part of the PL/SQL block as the GOTO statement.A GOTO in the execution section may not go to a label in the exception section; a GOTO in the exception section may not go to a label in the execution section. A GOTO in an exception handler may reference a label in the same handler. The following code example generates the same PL/SQL error shown in the previous section (PLS-00375):

BEGIN /* || The label and GOTO must be in the same section! */ GOTO out_of_here;EXCEPTION WHEN OTHERS THEN <<out_of_here>> /* Out of scope! */ NULL;END;

The target label must be in the same scope as the GOTO statement - student2.ru 4.4 The NULL Statement

Usually when you write a statement in a program, you want it to do something. There are cases, however, when you want to tell PL/SQL to do absolutely nothing, and that is where the NULL statement comes in handy. The NULL statement has the following format:

NULL;

Well, you wouldn't want ado-nothing statement to be complicated, would you? The NULL statement is simply the reserved word NULL followed by a semicolon (;) to indicate that this is a statement and not a NULL value. The NULL statement does nothing except pass control to the next executable statement.

Why would you want to use the NULL statement? There are several reasons, described in the following sections.

Наши рекомендации