在一个存储过程中有两个游标,而且第二个游标用到了第一个游标的值,这样的存储过程怎么写呢?以下是个例子:
create or replace procedure DYNAMIC_CONFIRM
as
cursor c1 is select o.id,o.cno,o.icorpid,o.iroeid, o.lr from ccs os inner join cc o on os.ids= o.id where o.istate=3 ;
v c1%rowtype;//把游标c1查询值的类型赋值给v
cno varchar(15);
begin
open c1;
loop
fetch c1 into v;
exit when c1% notfound;
update fc set fc.ibalance = v.lr;
DECLARE cursor c2 is SELECT ISMBID FROM FC_SECUMONEYB where FC_SECUMONEYB.IOUTCORPID=v.icorpid AND FC_SECUMONEYB.IDEPID=v.idepid;
v1 c2%rowtype;
begin //遍历第二个游标
open c2;
loop fetch c2 into v1;
exit when c2% notfound;
Insert Into FC_SECUMONEYR(IINCORPID,DDATE,IDEPID,ISETTLEBALANCE)Values(431,sysdate,v.idepid,v1.ISETTLEBALANCE) ;
end loop;
end;
end loop;
end;