Oracle PL/SQL - What is the output: References FOR LOOP Statement Index?

Question

What is the output of the following code?

BEGIN 
  FOR i IN 1..3 LOOP 
    DBMS_OUTPUT.PUT_LINE ('Inside loop, i is ' || TO_CHAR(i)); 
  END LOOP; 
   
  DBMS_OUTPUT.PUT_LINE ('Outside loop, i is ' || TO_CHAR(i)); 
END; 
/ 


Click to view the answer

DBMS_OUTPUT.PUT_LINE ('Outside loop, i is ' || TO_CHAR(i)); 
   * 
ERROR at line 6: 
ORA-06550: line 6, column 58: 
PLS-00201: identifier 'I' must be declared 
ORA-06550: line 6, column 3: 
PL/SQL: Statement ignored

Note

A statement outside the FOR LOOP statement references the loop index, causing an error.

Related Quiz