Found strange thing. Can't understand why Oracle allow this query and why cnt variable doesn't change after it's execution:
declare cnt number;
begin
for r in (Select count(1) into cnt from v$session) loop
dbms_output.put_line(cnt);
END LOOP;
end;
Select count(1) from v$session returns not null value
Of course I've understand:
- That
FORdoesn't need in this situation.CountwithoutINTOretuns only one row. - That I can use it without
INTOand it will works.
Just curious how and why it works in query above.
It's strange why Oracle allow subquery with SELECT INTO, because in common situation Oracle returns compilation error ORA-06550
declare cnt number;
begin
select count(1) from (Select count(1) into cnt from v$session)
end;
or
And if first query works - why it doesn't return cnt value correctly?
rlike a table row.