gpt4 book ai didi

oracle - 程序中出现奇怪错误 "Ora-01001 Invalid cursor"

转载 作者:行者123 更新时间:2023-12-04 10:27:39 31 4
gpt4 key购买 nike

昨天我研究了我们生产过程中的一个奇怪的错误。
语句执行失败

if v_cursor%isopen then
close v_cursor; -- here was an error
end if;

经过一番深入研究,我发现问题出在打开此游标的子程序中。我通过在子程序中添加输出参数 sys_refcursor 来修复错误。为了澄清情况,请考虑以下测试代码:

procedure nested_test(test  number,
p_cur out sys_refcursor)
is
procedure nested_procedure_fail is
begin
open p_cur for
select 1, 2, 3, 4
from dual
where 1 = 0;
end;

procedure nested_procedure_success(p_cur out sys_refcursor) is
begin
open p_cur for
select 1, 2, 3, 4
from dual
where 1 = 0;
end;

begin
if test = 1 then
nested_procedure_fail;
else
if test = 2 then
nested_procedure_success(p_cur => p_cur);
else
open p_cur for
select 6, 7, 8, 9
from dual
where 1 = 1;
end if;
end if;
end;

procedure test_fail is
v_cur sys_refcursor;
begin
nested_test(test => 1, p_cur => v_cur);
if v_cur%isopen then
close v_cur;
end if;
end;

procedure test_success is
v_cur sys_refcursor;
begin
nested_test(test => 2, p_cur => v_cur);
if v_cur%isopen then
close v_cur;
end if;
end;

如果我尝试运行 test_success一切正常,但在 test_fail我收到一条消息

ORA-01001: Invalid cursor



我找不到任何关于此的信息。谁能解释为什么这段代码失败?

甲骨文版本:

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Solaris: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production

最佳答案

这似乎是错误 7174888,或者至少是与其密切相关的错误。对此的描述是“当 sys_refcursor 传递给另一个过程时引发 ORA-6504”,但如果我更改 test_fail,我也可以做到这一点。做一个获取:

  procedure test_fail is
v_cur sys_refcursor;
a number;
b number;
c number;
d number;
begin
nested_test(test => 1, p_cur => v_cur);
if v_cur%isopen then
fetch v_cur into a,b,c,d;
close v_cur;
end if;
end;

我收到 ORA-06504: PL/SQL: Return types of Result Set variables or query do not match .

错误报告中的解决方法解决了获取和关闭问题。

Initialize the ref cursor to a non-NULL value at the highest level at which it will be accessed


  begin
/* Dummy open to avoid bug 7174888 */
open v_cur for 'select 1 from dual';
nested_test(test => 1, p_cur => v_cur);
if v_cur%isopen then
fetch v_cur into a,b,c,d;
close v_cur;
end if;
end;

关于oracle - 程序中出现奇怪错误 "Ora-01001 Invalid cursor",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11341166/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com