游标

-- 利用fetch...into 抓取游标数据 此种方式适用于数据量比较小的情况
declare
  v_id t_user.user_id%type;
  v_no t_user.user_no%type;
  cursor cur is select user_id,user_no from t_user;
  begin
    open cur;
    loop
      fetch cur into v_id,v_no;
      exit when cur%notfound;
      if v_id = '1004' then
         continue;
       else 
        dbms_output.put_line(v_id || '  ' || v_no);
      end if;
      
    end loop;
    close cur;-- 关闭游标
  end;
  
 -- 利用fetch... bulk collect into 
 --抓取游标数据 此种方式在数据量大的情况下效率高于fetch...into
 declare
   type user_type is table of t_user%rowtype;
   v_user user_type;
   cursor cur is
     select * from t_user t;
     v_count number := 0;
 begin
   open cur;
  -- loop --这块也加了个循环,有点不太明白,目测是防止抓取数时候出现异常
     fetch cur bulk collect
       into v_user;
    -- exit when cur%notfound;--退出在此处无结果输出
     for i in 1 .. v_user.count loop
       dbms_output.put_line('id=' || v_user(i).user_id || '  name==' || v_user(i)
                            .user_name);
     end loop;
     v_count := v_count + 1;
     --exit when cur%notfound;--退出在此处正确输出结果
  -- end loop;
   dbms_output.put_line('count==' || v_count);
   close cur;
 end;
 
--
declare
  cursor cur is
    select * from t_user;
begin
  for v_user in cur loop
    dbms_output.put_line('id is ' || v_user.user_id || '   name is ' ||
                         v_user.user_name);
  end loop;
end;
    
   
   
   
   
   
   
   
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值