首页 > 数据库技术 > 详细

oracle遍历游标

时间:2015-05-24 12:43:22      阅读:299      评论:0      收藏:0      [点我收藏+]

1,while循环

declare
  v_tname varchar2(20);
  cursor c_tname is select a.TABLE_NAME from user_tables a where a.TABLESPACE_NAME = VTMDATA;
begin  
  open c_tname;
  fetch c_tname into v_tname;
  while c_tname%found loop 
     dbms_output.put_line(v_tname);
     fetch c_tname into v_tname;  --此处必须fetch否则就一直取第一个造成死循环
  end loop;
  close c_tname;                  --要手动关闭游标否则不能再次使用
end;

2,for循环

declare
  cursor c_tname is select a.TABLE_NAME from user_tables a where a.TABLESPACE_NAME = VTMDATA;
begin  
  for tname in c_tname
  loop
      dbms_output.put_line(tname.table_name);  --通过"." 操作符去对应的列
  end loop;                                    --循环完成之后自动关闭游标,无需手动关闭
exception
  when others then
    dbms_output.put_line(sqlcode);
    dbms_output.put_line(sqlerrm);
end;

oracle遍历游标

原文:http://www.cnblogs.com/kokom/p/4525568.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!