Table of Contents Previous Next



The GOTO statement causes the point of execution to jump to the statement with the specified label. The syntax of a GOTO statement is:
GOTO label
label is a name assigned to an executable statement. label must be unique within the scope of the function, procedure or anonymous block.
<<label>> statement
statement is the point of execution that the program jumps to.
You can label assignment statements, any SQL statement (like INSERT, UPDATE, CREATE, etc.) and selected procedural language statements. The procedural language statements that can be labeled are:
GET DIAGNOSTICS
Please note that exit is considered a keyword, and cannot be used as the name of a label.
GOTO statements cannot transfer control into a conditional block or sub-block, but can transfer control from a conditional block or sub-block.
The following example verifies that an employee record contains a name, job description, and employee hire date; if any piece of information is missing, a GOTO statement transfers the point of execution to a statement that prints a message that the employee is not valid.
GOTO statements have the following restrictions:
A GOTO statement cannot jump to a declaration.
A GOTO statement cannot transfer control to another function or procedure.
A label should not be placed at the end of a block, function or procedure.


Table of Contents Previous Next