提交数据库后游标继续取值问题

    提交了数据库后,游标能否接着取值。

    实验如下:

    CUSTOMER表:

    CUSTOMERID NAME                 LOCATION
---------- -------------------- --------------------
       201          Dennis               海淀
       202          John                  朝阳
       203          Tom                  东城
       204          Jenny                东城
       205          Rick                   西城

    存储过程:

 create or replace procedure Hello is
        cur_result customer%rowtype;
        i number;
        cursor cur_select is select CUSTOMERID,NAME,LOCATION from customer;
    begin
        i := 0;
        open cur_select;
        dbms_output.put_line('开始');

    --第一次循环取值
    loop
        i := i + 1;
        fetch cur_select into cur_result;
        if cur_select%notfound then
            dbms_output.put_line('exit 第一次取值');
            exit;
        end if;
        dbms_output.put_line('第一次'||i||'='||cur_result.name);
        if i = 2 then
            dbms_output.put_line('第一次提交'||i||'='||cur_result.name);
            commit;
            exit;
        end if;
    end loop;

    --第二次循环取值
    loop
        i := i + 1;
        fetch cur_select into cur_result;
        if cur_select%notfound then
            dbms_output.put_line('exit 第二次取值'');
            exit;
        end if;
        dbms_output.put_line('第二次'||i||'='||cur_result.name);
    end loop;
    close cur_select;
end Hello;
/

 

 

   ********************************************

结果如下:

开始
第一次1=Dennis
第一次2=John
第一次提交2=John
第二次3=Tom
第二次4=Jenny
第二次5=Rick
exit 第二次取值

********************************************

 

证明,提交了数据库后,没有关闭游标,无需打开,继续可以取值

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值