本人刚学oracle,菜鸟问题请谅解
这是我创建的表
create table lz(
id   number(2),
name  varchar2(10)
);
-------------------------------------
begin
for i in 1..10 loop
insert into lz values(i,'niit'||i);
end loop;
end;
/
commit;这个第二步
declare
cursor v_cur is select id,name from lz order by id ;
v_row lz%rowtype;
begin
open v_cur;
fetch v_cur into v_row;
while v_cur%found loop
dbms_output.put_line('id:'||v_row.id||'name:'||v_row.name);
fetch v_cur into v_row;
end loop;
close v_cur;
end;
/
下面是问题
begin
for hello in (select id,name from lz order by id DESC) loop
dbms_output.put_line('id:'||hello.id||'name:'||hello.name);
end loop;
end;
/
此处的hello改成任何一个都可以,和游标作用一样,为什么?????本人小白,请各位从简单说

解决方案 »

  1.   

    这个是plsql 中for的特性  自动申明的变量 类型是根据 你in后面的类型定的
      

  2.   

    hello 为隐式游标,事先不需声明。
      

  3.   

    这个是plsql 中for的特性 自动申明的变量 类型是根据 你in后面的类型定的
      

  4.   

    隐式游标用于 FOR LOOP 循环语句中,并且只能在 loop 块中使用;事先不需要 open;退出 for loop 循环后,隐式用户游标会被自动关闭。
      

  5.   

    游标for循环是显示游标的一种快捷使用方式,它使用for循环依次读取结果集中的行数据,当form循环开始时,游标自动打开(不需要open),每循环一次系统自动读取游标当前行的数据(不需要fetch),当退出for循环时,游标被自动关闭(不需要使用close)。使用游标for循环的时候不能使用open语句,fetch语句和close语句,否则会产生错误。