ORA-24338: 未执行语句句柄
这个问题主要出现在使用数据库游标的时候.当执行存储过程,返回的游标没有打开时,可能会报这个错。
游标没有打开的情况一般是忘记了写打开游标的语句,也可能是存储过程中执行出错,导致最后游标未打开。
如:
Code
CREATE OR REPLACE package BODY PK_PROFU_GetMtStopTimesInfo
is procedure GetMtStopTimesInfo
(
mMtName varchar2,
mycs out mytype
)
as
v_count int:=0;
begin
select count(1) INTO v_count
FROM WPStopTimesInfo t,MachineTools s
WHERE s.matolname=mMtName AND t.mtid=s.matolid;
if(v_count>0) then
open mycs for select w.matolname , v.stoptimes
FROM WPStopTimesInfo v,MachineTools w
WHERE w.matolname=mMtName AND v.mtid=w.matolid
order by v.stoptimes desc ;
end if;
END;
end;
CREATE OR REPLACE package BODY PK_PROFU_GetMtStopTimesInfo
is procedure GetMtStopTimesInfo
(
mMtName varchar2,
mycs out mytype
)
as
v_count int:=0;
begin
select count(1) INTO v_count
FROM WPStopTimesInfo t,MachineTools s
WHERE s.matolname=mMtName AND t.mtid=s.matolid;
if(v_count>0) then
open mycs for select w.matolname , v.stoptimes
FROM WPStopTimesInfo v,MachineTools w
WHERE w.matolname=mMtName AND v.mtid=w.matolid
order by v.stoptimes desc ;
end if;
END;
end;
当上面的变量 v_count=0 时,将出现上述错误.
将其修改成如下所示,问题解决.
Code
CREATE OR REPLACE package BODY PK_PROFU_GetMtStopTimesInfo
is procedure GetMtStopTimesInfo
(
mMtName varchar2,
mycs out mytype
)
as
v_count int:=0;
begin
select count(1) INTO v_count
FROM WPStopTimesInfo t,MachineTools s
WHERE s.matolname=mMtName AND t.mtid=s.matolid;
if(v_count>0) then
open mycs for select w.matolname , v.stoptimes
FROM WPStopTimesInfo v,MachineTools w
WHERE w.matolname=mMtName AND v.mtid=w.matolid
order by v.stoptimes desc ;
else
open mycs for select mMtName as matolname,1 as stoptimes from dual;
end if;
END;
end;
CREATE OR REPLACE package BODY PK_PROFU_GetMtStopTimesInfo
is procedure GetMtStopTimesInfo
(
mMtName varchar2,
mycs out mytype
)
as
v_count int:=0;
begin
select count(1) INTO v_count
FROM WPStopTimesInfo t,MachineTools s
WHERE s.matolname=mMtName AND t.mtid=s.matolid;
if(v_count>0) then
open mycs for select w.matolname , v.stoptimes
FROM WPStopTimesInfo v,MachineTools w
WHERE w.matolname=mMtName AND v.mtid=w.matolid
order by v.stoptimes desc ;
else
open mycs for select mMtName as matolname,1 as stoptimes from dual;
end if;
END;
end;