日期:2014-05-17  浏览次数:21031 次

关于两层游标的用法的疑问
一直用sqlserver,没有用过oracle,现在写了个存储过程,用两层游标,语法有问题?还是oracle不能这么写?


代码;
 create or replace procedure updatetime is 

  v_jtdid NUMBER;
 v_audittaskid VARCHAR2(10);

cursor cursor1 is select * from (select jd.jtdid from tz_jobtypedetail jd where jd.jtid = 1001 order by jd.orderno ) where rownum < 5 ;


 
begin

open cursor1;
fetch cursor1 into v_jtdid;
while cursor1%found loop
begin


 

CURSOR cursor2 is select * from ( select a.audittaskid,a.creattime,a.orderdate,a.releasedate from tz_audittaskrelease a where a.categoryid = v_jtdid order by trunc(dbms_random.value(0, 1000))) where rownum < 13;

begin
  open cursor2;
  fetch cursor2 into v_audittaskid;
  while cursor2%found loop
  begin
  update tz_audittaskrelease set creattime = sysdate ,orderdate = sysdate ,releasedate = sysdate where audittaskid = v_audittaskid;
  end
  fetch cursor2 into v_audittaskid;  
end loop;
close cursor2;
end;


fetch cursor1 into v_jtdid;  
end;
end loop;

close cursor1;

end;


------解决方案--------------------
把CURSOR cursor2 is select * from 的定义拿到Cursor1和begin之间定义。