我刚刚发现了Oracle中PLSQL和SQL之间某些意外的行为差异。
如果我在SQLDeveloper上运行这个查询,我会得到5个结果:
select level lvl from dual connect by level <=5;
但如果我在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;
变量w_counter以值1结束(奇怪)
但最奇怪的是,如果我将查询封装在子查询中...就像这样:
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;
w_counter变量以值5结束...
对此,你有什么要说的吗?
我正在使用Oracle 9.2i。