微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

oracle 游标使用

游标可以理解为一个查询集合;使用时先申明游标; 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.jb51.cc/oracle/213489.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐