gpt4 book ai didi

oracle - ORA-24338 : Statement handle not executed

转载 作者:行者123 更新时间:2023-12-03 15:48:37 27 4
gpt4 key购买 nike

我正在使用 Delphi 7、Oracle 10 和 ODAC 组件。

从 LoadTrainResult 方法中,我调用了storedProc。

    procedure TfrmTrain.LoadTrainResult;  
begin
StoredProc.StoredProcName := 'PTRAIN.QTRAIN';
StoredProc.Prepare;
try
StoredProc.ParamByName('P_COURSE').AsString := CurrentSearch.Course;
StoredProc.ParamByName('P_TOPIC').AsString := CurrentSearch.Topic;
StoredProc.ParamByName('P_EMP').AsString := CurrentSearch.Emp;
StoredProc.Open;
finally
StoredProc.Close;
end;
end;

架构是

    Create or replace PACKAGE TRAIN.pTRAIN  IS 
TYPE CursorType IS REF CURSOR;
PROCEDURE QTRAIN (p_CursorVar OUT CursorType, p_Course in VarChar2,
p_Topic in out VarChar2, p_emp in Varchar 2 );
END TRAIN.pTRAIN;

create or replace PACKAGE BODY TRAIN.pTRAIN IS
PROCEDURE QTRAIN (p_CursorVar OUT CursorType, p_Course in VarChar2,
p_Topic in out VarChar2, p_emp in Varchar 2 )

IS
BEGIN
if p_course is not null then
OPEN p_cursorvar for
select * from train.course
where course = p_Course;
elsif p_topic is not null then
OPEN p_cursorvar for
select *
from train.topic
where topic = p_topic;
end if;
Exception
WHEN OTHERS THEN
p_TOPIC := '';
END QTRAIN;
END TRAIN.pTRAIN;

当我编译包时,我没有收到任何错误。然而,当我运行应用程序时,我收到错误 ORA-24338:语句句柄未执行。我调试了我的应用程序,发现错误发生在 StoredProc.Prepare;不在 StoredProc.ExecProc 处;

我读了很多关于 ORA-24338 的帖子,但我无法找出我的代码出了什么问题。

我发现当我在存储过程中添加 else 条件时我没有收到错误。

修改后的Proc为

    create or replace PACKAGE BODY  TRAIN.pTRAIN  IS  
PROCEDURE QTRAIN (p_CursorVar OUT CursorType, p_Course in VarChar2,
p_Topic in out VarChar2, p_emp in Varchar 2 )
IS
BEGIN
if p_course is not null then
OPEN p_cursorvar for
select * from train.course
where course = p_Course;

elsif p_topic is not null then
OPEN p_cursorvar for
select * from train.topic
where topic = p_topic

else
OPEN p_cursorvar for
select * from emp whhere empid = p_emp;

end if;
Exception
WHEN OTHERS THEN
p_TOPIC := '';
END QTRAIN;
END TRAIN.pTRAIN;

其实我不想要其他条件。有什么办法可以消除这个错误吗?

最佳答案

在我看来,问题是:在存储过程的第一个版本中,可能没有结果集可返回,但在第二个版本中,您在最后一个版本中提供了结果集。

当我们通过查看完整的错误报告了解 ORA-24338 的含义时,我的怀疑更加强烈:

Error: ORA-24338
Text: statement handle not executed
---------------------------------------------------------------------------
Cause: A fetch was attempted before executing a statement handle.
Action: Execute a statement and then fetch the data.

已尝试提取,但在某些情况下,没有任何结果集可供提取,直到您向其提供最后一个 else 为止。

您的存储过程通过输出参数返回游标,因此您始终必须打开该游标。在代码的第一个版本中,您没有。

关于oracle - ORA-24338 : Statement handle not executed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11991773/

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