0

I'm quite new at PL SQL, when I tried to write sth like below:

BEGIN FOR foo IN (SELECT A, B, C FROM foo_table WHERE some_conditions) LOOP
DBMS_OUTPUT.PUT_LINE('sth here')
END LOOP;

I got following error while executing statment in SQL Developer

Encountered the symbol "end-of-file" when expecting is one the following: begin case declare end exception and more...

What's wrong with my statement? Could anyone give me a tip how to resolve this? I'll be very glad for all hints.

Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
  • 1
    PL/SQL uses semi-colon (;) line endings... if that is your actual code start there: http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/controlstructures.htm – tawman Feb 15 '12 at 22:12
  • ooops, i forgot about it in my example, In origin code it's END LOOP; and the error is like I wrote in my first post. updated, but I got the error when semicolon already was placed in my code. – user1212503 Feb 15 '12 at 22:17

2 Answers2

9

As well as missing the ; an end; is missing too. This code should work:

BEGIN FOR foo IN (SELECT A, B, C FROM foo_table WHERE some_conditions) LOOP
DBMS_OUTPUT.PUT_LINE('sth here');
END LOOP;
END;
John Doyle
  • 7,475
  • 5
  • 33
  • 40
1

You are missing the end keyword to close off the begin.

This kind of thing tends to jump out at you when you format your code.

begin
    for foo in (
        select a, b, c from foo_table where some_conditions
    )
    loop
        dbms_output.put_line('sth here');
    end loop;

(Edit: somehow I missed John's correct reply before posting.)

William Robertson
  • 15,273
  • 4
  • 38
  • 44