未找到游标上下文

Corn1 2010-10-22 10:29:44
我在程序里面调用oracle存储过程,报错:ORA-01023 未找到游标上下文,但存储过程里面游标确实已经打开。不知道怎么回事。
存储过程如下:


create or replace procedure pr_CA_GetCardNoList
(
p_key number,
p_SchoolID number,
p_Address number,
p_Cursor out pk_Public.Cur
)
as
begin
case
when p_key = 0 then
execute immediate 'truncate table T_CA_TempRedList';
insert into T_CA_TempRedList(trCardNo, trInternalID)
select distinct a.icCardNo, a.icInternalID from T_CA_IssueCardChild a,
(select icCardNo, max(icTime) as MaxTime from T_CA_IssueCardChild group by icCardNo) b
where a.icSchoolID = p_SchoolID and a.icIsNew = 0 and a.icCardNo = b.icCardNo and a.icTime = b.MaxTime
and not (a.icTypeID in (3, 4) or (a.icTypeID = 2 and (a.icRepTypeID != 5 or a.icRepTypeID is null)))
union all
select distinct a.icCardNo, a.icInternalID from T_CA_IssueCardTeacher a,
(select icCardNo, max(icTime) as MaxTime from T_CA_IssueCardTeacher group by icCardNo) b
where a.icSchoolID = p_SchoolID and a.icIsNew = 0 and a.icCardNo = b.icCardNo and a.icTime = b.MaxTime
and not (a.icTypeID in (3, 4) or (a.icTypeID = 2 and (a.icRepTypeID != 5 or a.icRepTypeID is null)));

execute immediate 'truncate table T_CA_TempBlackList';
insert into T_CA_TempBlackList(tbCardNo, tbInternalID)
select distinct a.icCardNo, a.icInternalID from T_CA_IssueCardChild a,
(select icCardNo, max(icTime) as MaxTime from T_CA_IssueCardChild group by icCardNo) b
where a.icSchoolID = p_SchoolID and a.icIsNew = 0 and a.icCardNo = b.icCardNo and a.icTime = b.MaxTime
and (a.icTypeID in (3, 4) or (a.icTypeID = 2 and (a.icRepTypeID != 5 or a.icRepTypeID is null)))
union all
select distinct a.icCardNo, a.icInternalID from T_CA_IssueCardTeacher a,
(select icCardNo, max(icTime) as MaxTime from T_CA_IssueCardTeacher group by icCardNo) b
where a.icSchoolID = p_SchoolID and a.icIsNew = 0 and a.icCardNo = b.icCardNo and a.icTime = b.MaxTime
and (a.icTypeID in (3, 4) or (a.icTypeID = 2 and (a.icRepTypeID != 5 or a.icRepTypeID is null)));

delete from T_CA_RedList where rlSchoolID = p_SchoolID and rlAddress = p_Address and rlCardNo not in
(select trCardNo from T_CA_TempRedList);
delete from T_CA_BlackList where blSchoolID = p_SchoolID and blAddress = p_Address and blCardNo not in
(select tbCardNo from T_CA_TempBlackList);

open p_Cursor for
select tbInternalID as InternalID, tbCardNo as CardNo, 0 as BlackRed from T_CA_TempBlackList
where tbCardNo not in (select blCardNo from T_CA_BlackList where blSchoolID = p_SchoolID and blAddress = p_Address)
union all
select trInternalID as InternalID, trCardNo as CardNo, 1 as BlackRed from T_CA_TempRedList
where trCardNo not in (select rlCardNo from T_CA_RedList where rlSchoolID = p_SchoolID and rlAddress = p_Address)
order by BlackRed, InternalID;
return;
end case;
commit;
exception
when others then
rollback;
end pr_CA_GetCardNoList;

...全文
252 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
心中的彩虹 2010-10-22
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 corn1 的回复:]
引用 8 楼 ngx20080110 的回复:
引用 6 楼 corn1 的回复:
nGX20080110,我该怎样得到出错信息?确实是在open之前就已出错,但就是不知道哪一步出错。
还有,为什么我在plsql里面调试成功呢?

你試一下,刪除掉exception的那部分,讓oracle拋出異常,然後在你的程序裡捕獲該異常,然後打印出來看看是什麼出錯了。


错误提示:资源正忙,……
[/Quote]
此表不止你一个人在dml 你不就是要清空数据 改成临时表 试试
minitoy 2010-10-22
  • 打赏
  • 举报
回复
T_CA_TempRedList改成临时表.
gelyon 2010-10-22
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 corn1 的回复:]
nGX20080110,我该怎样得到出错信息?确实是在open之前就已出错,但就是不知道哪一步出错。
还有,为什么我在plsql里面调试成功呢?
[/Quote]
调试只是单纯的你这个procedure从语法上来说是正确的,至于你程序中调用它引发的错误,是你程序原因,估计是你游标未关闭,你看看呢
Corn1 2010-10-22
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 ngx20080110 的回复:]
引用 6 楼 corn1 的回复:
nGX20080110,我该怎样得到出错信息?确实是在open之前就已出错,但就是不知道哪一步出错。
还有,为什么我在plsql里面调试成功呢?

你試一下,刪除掉exception的那部分,讓oracle拋出異常,然後在你的程序裡捕獲該異常,然後打印出來看看是什麼出錯了。
[/Quote]

错误提示:资源正忙,但指定以NOWAIT方式获取资源
定位在line24,
execute immediate 'truncate table T_CA_TempBlackList'; 这行。
晕掉了,该怎么改啊?
ngx20080110 2010-10-22
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 corn1 的回复:]
nGX20080110,我该怎样得到出错信息?确实是在open之前就已出错,但就是不知道哪一步出错。
还有,为什么我在plsql里面调试成功呢?
[/Quote]
你試一下,刪除掉exception的那部分,讓oracle拋出異常,然後在你的程序裡捕獲該異常,然後打印出來看看是什麼出錯了。
Corn1 2010-10-22
  • 打赏
  • 举报
回复
有没有类似于GetLastError之类的功能?
Corn1 2010-10-22
  • 打赏
  • 举报
回复
nGX20080110,我该怎样得到出错信息?确实是在open之前就已出错,但就是不知道哪一步出错。
还有,为什么我在plsql里面调试成功呢?
心中的彩虹 2010-10-22
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wkc168 的回复:]
引用楼主 corn1 的回复:
我在程序里面调用oracle存储过程,报错:ORA-01023 未找到游标上下文,但存储过程里面游标确实已经打开。不知道怎么回事。
存储过程如下:


SQL code

create or replace procedure pr_CA_GetCardNoList
(
p_key number,
p_SchoolID number,
p_Ad……
[/Quote]
还有一种可能就是游标没释放
心中的彩虹 2010-10-22
  • 打赏
  • 举报
回复
[Quote=引用楼主 corn1 的回复:]
我在程序里面调用oracle存储过程,报错:ORA-01023 未找到游标上下文,但存储过程里面游标确实已经打开。不知道怎么回事。
存储过程如下:


SQL code

create or replace procedure pr_CA_GetCardNoList
(
p_key number,
p_SchoolID number,
p_Address numbe……
[/Quote]
在调用的块里面加个判断 cur%isopen

或者把commit;的位置放到打开游标的前面


gelyon 2010-10-22
  • 打赏
  • 举报
回复
你 p_Cursor out pk_Public.Cur这个动态游标,程序中是否每次close关闭了,必须先关闭才能再次执行过程打开游标!
ngx20080110 2010-10-22
  • 打赏
  • 举报
回复
可能在open之前就已經出錯,而你的exception部分,除了rollback,沒有其他操作,無法獲取更多信息了。
Corn1 2010-10-22
  • 打赏
  • 举报
回复
而且用pl/sql 的“测试”窗口,测试通过的,返回结果集也正确。就是程序里面调用不行。

17,382

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧