我在程序里面调用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;

解决方案 »

  1.   

    而且用pl/sql 的“测试”窗口,测试通过的,返回结果集也正确。就是程序里面调用不行。
      

  2.   

    可能在open之前就已經出錯,而你的exception部分,除了rollback,沒有其他操作,無法獲取更多信息了。
      

  3.   

    你 p_Cursor out pk_Public.Cur这个动态游标,程序中是否每次close关闭了,必须先关闭才能再次执行过程打开游标!
      

  4.   

    在调用的块里面加个判断 cur%isopen 或者把commit;的位置放到打开游标的前面
      

  5.   

    nGX20080110,我该怎样得到出错信息?确实是在open之前就已出错,但就是不知道哪一步出错。
    还有,为什么我在plsql里面调试成功呢?
      

  6.   

    有没有类似于GetLastError之类的功能?
      

  7.   

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

  8.   


    错误提示:资源正忙,但指定以NOWAIT方式获取资源
    定位在line24,
    execute immediate 'truncate table T_CA_TempBlackList';  这行。
    晕掉了,该怎么改啊?
      

  9.   

    调试只是单纯的你这个procedure从语法上来说是正确的,至于你程序中调用它引发的错误,是你程序原因,估计是你游标未关闭,你看看呢
      

  10.   

    此表不止你一个人在dml 你不就是要清空数据 改成临时表 试试