Oracle PL/SQL - PL SQL Statement GOTO Statement

Introduction

The following code shows how to use GOTO Statement.

Demo

SQL>
SQL> DECLARE-- from   w w w .  ja v a  2s .  co m
  2    p  VARCHAR2(30);
  3    n  PLS_INTEGER := 37;
  4  BEGIN
  5    FOR j in 2..ROUND(SQRT(n)) LOOP
  6      IF n MOD j = 0 THEN
  7        p := ' is not a prime number';
  8        GOTO print_now;
  9      END IF;
 10    END LOOP;
 11
 12    p := ' is a prime number';
 13
 14    <<print_now>>
 15    DBMS_OUTPUT.PUT_LINE(TO_CHAR(n) || p);
 16  END;
 17  /
37 is a prime number

PL/SQL procedure successfully completed.

SQL>

Related Topics

Quiz