← PL/SQL Topics

Language Basics

Explain the GOTO and CONTINUE statements in PL/SQL loops

GOTO and CONTINUE

Oracle Fusion / EBS · Technical · PL/SQL

GeneralHigh confidence

CONTINUE skips to the next loop iteration; GOTO jumps unconditionally to a labeled statement.

Grounded in: Curated Oracle knowledge layer — PL/SQL

How it works

CONTINUE [WHEN condition] skips the rest of the current loop iteration and moves straight to the next one. GOTO <<label>> transfers control unconditionally to a labeled statement within the same block's flow — it can't jump into a loop, IF, or sub-block from outside it, or out of a subprogram, and is generally discouraged in favor of structured control (IF/loops/EXIT) except for a few specific idioms.

How it works
BEGIN
  FOR v_i IN 1..5 LOOP
    CONTINUE WHEN MOD(v_i, 2) = 0;
    DBMS_OUTPUT.PUT_LINE('Odd: ' || v_i);
  END LOOP;

  FOR v_i IN 1..5 LOOP
    IF v_i = 3 THEN
      GOTO skip_print;
    END IF;
    DBMS_OUTPUT.PUT_LINE('Value: ' || v_i);
    <<skip_print>>
    NULL;
  END LOOP;
END;
/

Related Questions

Have a follow-up, or a different question?

Continue in Ask Oracle AI