Oracle PL/SQL - GOTO Statement Transfers Control to Enclosing Block

Introduction

A GOTO statement can transfer control to an enclosing block from the current block.

Demo

SQL>
SQL> drop TABLE emp;

Table dropped.-- from  w  w  w .  j  a va 2  s  . com

SQL>
SQL> CREATE TABLE emp(
  2  empid NUMBER(6),
  3  first_name VARCHAR2(20),
  4  last_name VARCHAR2(25)) ;
SQL>
SQL> INSERT INTO emp VALUES( 100, 'Steven', 'King');
SQL> INSERT INTO emp VALUES( 101, 'Mary', 'Smith');
SQL>
SQL>
SQL> DECLARE
  2    v_last_name  VARCHAR2(25);
  3    v_emp_id     NUMBER(6) := 120;
  4  BEGIN
  5    <<get_name>>
  6    SELECT last_name INTO v_last_name
  7    FROM emp
  8    WHERE empid = v_emp_id;
  9
 10    BEGIN
 11      DBMS_OUTPUT.PUT_LINE (v_last_name);
 12      v_emp_id := v_emp_id + 5;
 13
 14      IF v_emp_id < 120 THEN
 15        GOTO get_name;
 16      END IF;
 17    END;
 18  END;
 19  /
DECLARE
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 6


SQL>

Related Topic