I just found what I think is somewhat unexpected behavior in PLSQL vs SQL in Oracle.
If I run this query on SQLDeveloper I get 5 results:
select level lvl from dual connect by level <=5;
But if i run this statement in SQLDeveloper:
declare
w_counter number :=0;
begin
for REC in (select level lvl from dual connect by level <=5)
loop
w_counter := w_counter+1;
end loop;
dbms_output.put_line('W_COUNTER: '|| w_counter);
end;
The variable w_counter finishes with value 1 (weird)
but the weirdest part is that if I encapsulate the query in a subquery... something like:
declare
w_counter number :=0;
begin
for REC in (select * from (select level lvl from dual connect by level <=5))
loop
w_counter := w_counter+1;
end loop;
dbms_output.put_line('W_COUNTER: '|| w_counter);
end;
The w_counter variable finishes with value 5...
What do you have to say to this?
I am using Oracle 9.2i
5
for both blocks in Oracle 11g. Unfortunately I dont have 9i! – Philipsonselect rownum from dual connect by level <=5
instead? – Adaptable