0

Error starting at line 1 in command:

DECLARE
   x NUMBER := 0;
   counter NUMBER := 0;
BEGIN
   FOR i IN 1..4 LOOP
      x := x + 1000;
      counter := counter + 1;
      INSERT INTO temp VALUES (x, counter, 'in OUTER loop');
      END;
   END LOOP;
   COMMIT;
END;

Error report:

ORA-06550: line 11, column 10:
PLS-00103: Encountered the symbol ";" when expecting one of the following:

loop
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:
Community
  • 1
  • 1
Abhiruchi Sharma
  • 55
  • 1
  • 2
  • 9

2 Answers2

4

You don't need PL/SQL for this insert pattern. The following works in pure SQL:

create table temp(x number, counter number, text varchar2(20));

insert into temp
select (rownum-1)*1000, rownum-1, 'in OUTER loop'
from dual
connect by level <=4;
Colin 't Hart
  • 7,372
  • 3
  • 28
  • 51
2

The first END; on line 11 should not be there:

DECLARE
   x NUMBER := 0;
   counter NUMBER := 0;
BEGIN
   FOR i IN 1..4 LOOP
      x := x + 1000;
      counter := counter + 1;
      INSERT INTO temp VALUES (x, counter, 'in OUTER loop');
   END LOOP;
   COMMIT;
END;

You would only need it if you had a sub-block around the INSERT (say), for example for specific exception handling.

It would also be better generally to specify the column names in the INSERT:

      INSERT INTO temp(col1, col2, col3) VALUES (x, counter, 'in OUTER loop');
Alex Poole
  • 183,384
  • 11
  • 179
  • 318