Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1531652
  • 博文数量: 1647
  • 博客积分: 80000
  • 博客等级: 元帅
  • 技术积分: 9980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 15:15
文章分类

全部博文(1647)

文章存档

2011年(1)

2008年(1646)

我的朋友

分类:

2008-10-28 18:27:20


  我们在过程中需要遍历一张表,应该怎样做。我想大多少的人第一个念头就是Cursor。
  
  比如:
  
  create or replace procedure StudyCursor(
  resulst out integer
  ) is
  v_tablename varchar(30);
  v_tabletype varchar(11);
  cursor mycursor is select * from cat;
  begin
  open mycursor;
  loop
  fetch mycursor into v_tablename,v_tabletype;
  
  null; --you can use tablename and v_tabletype
  end loop;
  close mycursor;
  end StudyCursor;
  
  最近在看代码是,发现其实我们还有一个更方便的方法就是使用for in loop … end loop
  
  create or replace procedure StudyFor(
  resulst out integer
  ) is
  begin
  for emm in(select * from cat) loop
  null; --you can use emm.table_name and emm.table_type
  end loop;
  return ;
  end StudyFor;
  
  是不是更方便,我要使用的查询结果,只需使用emm.table_name和emm.table_type即可。
  
  查找了的官方文档,似乎没有看见for loop的此种用法。确实很奇妙,只是不知道oracle内部具体的实现方法。
【责编:admin】

--------------------next---------------------

阅读(210) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~