PL/SQL:GOTO Statement
The GOTO statement performs unconditional branching to a named Label in the program.Label should contain at least one executable statement.The structure of PL/SQL is such that the GOTO statement is rarely needed.Overuse of GOTO statements can result in complex, unstructured code that is hard to understand and maintain. So, use GOTO statements sparingly.
syntax is as follows:
GOTO label_name;
Label_name is the name of the label created with the syntax
<<LABEL_NAME>>
The following example shows Use of GOTO in an anonymous block:
BEGIN
DBMS_OUTPUT.PUT_LINE(‘BEGINNING OF PL/SQL BLOCK’);
GOTO Last_Section;
DBMS_OUTPUT.PUT_LINE(‘GOTO Fails’);
RETURN;
<<Last_Section>>
DBMS_OUTPUT.PUT_LINE(‘Program Ends Here’);
END;
/
Rules to remember regarding GOTOs:
■ GOTO statement cannot reference a label in a nested block.
■ GOTO statement cannot be executed outside an IF statement to a label inside the IF statement.
■ GOTO statement cannot be executed from inside an IF statement to a label inside another IF statement.
■ GOTO statement cannot navigate from the EXCEPTION section to any other section of the block.