Thursday, September 15, 2011

GOTO AND LABELS

GOTO AND LABELS

Syntax:
            Goto label;

Where label is a label defined in the PL/SQL block. Labels are enclosed in double angle brackets. When a goto statement is evaluated, control immediately passes to the statement identified by the label.
Ex:
BEGIN
     For i in 1..5 loop
            dbms_output.put_line('i = ' || i);
            if i = 4 then
               goto exit_loop;
            end if;
     end loop;
     <<exit_loop>>
     Null;
END;

Output:
                        i = 1
i = 2
i = 3
i = 4

RESTRICTIONS ON GOTO

Ø  It is illegal to branch into an inner block, loop.
Ø  At least one executable statement must follow.
Ø  It is illegal to branch into an if statement.
Ø  It is illegal to branch from one if statement to another if statement.
Ø  It is illegal to branch from exception block to the current block.

No comments:

Post a Comment

Oracle Escape Characters

Oracle allows the assignment of special escape characters to tell Oracle that the character is interpreted literally.  Certain characters ...