游标可以理解为一个查询集合;使用时先申明游标; declare cursor cursorName is select子句; 使用时用for循环调用即可;
for xx in cursorName loop doSomething end loop;
这样就可以了;xx代表select结果的一条记录,使用xx.id就表示要取该记录的id字段值;下面是一个存过完整的例子
declare cursor mainTask is select m.id from sys_monthtask_main m left join sys_month_task_basicdata d on m.basdataid=d.id where d.month='2016-07' ; begin for task in mainTask loop update sys_monthtask_main m set m.tal4done=(select count(1) from sys_monthtask_sub s where s.parentid=task.id and s.goal=4 and s.done>=s.goal) where m.id=task.id; update sys_monthtask_main m set m.tal7done=(select count(1) from sys_monthtask_sub s where s.parentid=task.id and s.goal=7 and s.done>=s.goal) where m.id=task.id; update sys_monthtask_main m set m.tal10done=(select count(1) from sys_monthtask_sub s where s.parentid=task.id and s.goal=10 and s.done>=s.goal) where m.id=task.id; update sys_monthtask_main m set m.tal15done=(select count(1) from sys_monthtask_sub s where s.parentid=task.id and s.goal=15 and s.done>=s.goal) where m.id=task.id; update sys_monthtask_main m set m.tal20done=(select count(1) from sys_monthtask_sub s where s.parentid=task.id and s.goal=20 and s.done>=s.goal) where m.id=task.id; end loop; commit; end;原文链接:https://www.f2er.com/oracle/213489.html