Updated on 2023-10-31 GMT+08:00

GOTO Statements

The GOTO statement unconditionally transfers the control from the current statement to a labeled statement. The GOTO statement changes the execution logic. Therefore, use this statement only when necessary. Alternatively, you can use the EXCEPTION statement to handle issues in special scenarios. To run the GOTO statement, the labeled statement must be unique.

Syntax

label declaration ::=

goto statement ::=

Examples

Constraints

The GOTO statement has the following constraints:

  • The GOTO statement does not allow multiple labeled statements even if they are in different blocks.
  • The GOTO statement cannot transfer control to the IF, CASE, or LOOP statement.
  • The GOTO statement cannot transfer control from one IF clause to another, or from one WHEN clause in the CASE statement to another.
  • The GOTO statement cannot transfer control from an outer block to an inner BEGIN-END block.
  • The GOTO statement cannot transfer control from an EXCEPTION block to the current BEGIN-END block but can transfer to an outer BEGIN-END block.
  • If the labeled statement in the GOTO statement does not exist, you need to add the NULL statement.