Oracle PL/SQL - What is the output: Label Placement?

Question

What is the output of the following code?

DECLARE 
  done  BOOLEAN; 
BEGIN 
  FOR i IN 1..50 LOOP 
    IF done THEN 
       GOTO end_loop; 
    END IF; 
    <<end_loop>> 
  END LOOP; 
END; 
/ 
  


Click to view the answer

END LOOP; 
  * 
ERROR at line 9: 
ORA-06550: line 9, column 3: 
PLS-00103: Encountered the symbol "END" when expecting one of the following: 
 ( begin case declare exit for goto if loop mod null raise

Note

A label can appear only before a block or before a statement, not in a statement, as in Example 4-30.

To fix it, add a NULL statement.

Demo

SQL>
SQL> --GOTO Statement Goes to Labeled NULL Statement
SQL> DECLARE
  2    done  BOOLEAN;-- w w w . j a v  a 2 s. c o m
  3  BEGIN
  4    FOR i IN 1..50 LOOP
  5      IF done THEN
  6        GOTO end_loop;
  7      END IF;
  8      <<end_loop>>
  9      NULL;
 10    END LOOP;
 11  END;
 12  /

PL/SQL procedure successfully completed.

SQL>

Related Quiz