我正在使用 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;
其实我不想要其他条件。有什么办法可以摆脱错误。