oracle显式游标不关闭、不关闭就再次打开会不会报错?

部署运行你感兴趣的模型镜像

问题:在查看老代码的时发现同一个cur第一次使用后没关闭,又第二次使用,程序使用了
很久,一直没有发现问题,至少应用层是没有出问题。那到底oracle会不会抛出异常?

 

测试:
(A)

create or replace procedure proc_test
as
type cursor_type is ref cursor;
cur cursor_type;
v_begin date;
v_end date;
begin
   open cur for
      select sysdate from dual;
     fetch cur into v_begin;
    
     open cur for ----再次open
        select sysdate from dual;
        fetch cur into v_end;

        insert into proc_use_times(PROC_NAME,PROC_DESC,BEGIN_TIME,END_TIME)
        values('测试','测试',v_begin,v_end);
        commit;
     ----而且没有关闭

exception
  when others then
  raise_application_error(-20123,sqlcode||sqlerrm);
end;

begin
proc_test;
end;
/
select *
from proc_use_times p
where p.PROC_NAME='测试'

----得出一条记录并且没有抛出异常 答案是:A种情况下不会报错。

 

(B)

create or replace procedure proc_test
as
type cursor_type is ref cursor;
cur cursor_type;
v_begin date;
v_end date;
begin
   open cur for
      select sysdate from dual;
     fetch cur into v_begin;
    
     open cur for
        select sysdate from dual;
        fetch cur into v_end;

        insert into proc_use_times(PROC_NAME,PROC_DESC,BEGIN_TIME,END_TIME)
        values('测试','测试',v_begin,v_end);
        commit;
   close cur;----使用两次并且最后一次关闭

exception
  when others then
  raise_application_error(-20123,sqlcode||sqlerrm);
end

-------------答案同A 依然没有报错

 

(C)
create or replace procedure proc_test
as
type cursor_type is ref cursor;
cur cursor_type;
v_begin date;
v_end date;
begin
   open cur for ----第一次打开
      select sysdate from dual;
     fetch cur into v_begin;
    
     open cur for ---第二次打开
        select sysdate from dual;
        fetch cur into v_end;

        insert into proc_use_times(PROC_NAME,PROC_DESC,BEGIN_TIME,END_TIME)
        values('测试','测试',v_begin,v_end);
        commit;
   close cur;----第一次关闭
   close cur;----第二次关闭

exception
  when others then
  raise_application_error(-20123,sqlcode||sqlerrm);
end

oracle显式游标不关闭、不关闭就再次打开会不会报错?

-----------答案是出错了。报了异常,从A和B两个测试的基础上,不难发现,C的报错也是合情合理的。

原因是既然已经关闭了,那再次关闭的时候 就会发现找不到这个游标了@@

 

转载于:https://www.cnblogs.com/gracejiang/archive/2010/12/02/5890451.html

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值