正确的写法很多种,这里我以设置带参数的游标为例,将2个游标建立关系,再进行遍历不会出现问题。
  如下:

 

create or replace procedure myt
as
cursor te_v1 is
select id1,val1 from Temp1;
cursor te_v2(idv2 varchar2) is
select count(*) from temp2 where id2=idv2;
v1_t te_v1%rowtype;
numv varchar2(2);
begin
open te_v1;
loop
fetch te_v1 into v1_t;
exit when te_v1%notfound;
open te_v2(v1_t.id1);
fetch te_v2 into numv;
if numv=0
then
update TEMP1 set val1='0' where id1=v1_t.id1;
else
update TEMP1 set val1='1' where id1=v1_t.id1;
end if;
close te_v2;
end loop;
close te_v1;
end;

  ok,这种问题我们应该注意到