複数のカーソルを使用する 2 つのデータベース プロシージャを Oracle で作成しました。直面する問題は、98% のケースでエラーなしでプロシージャが実行される一方で、いくつかのケースでエラー - ORA-01001 無効なカーソルがスローされることです。
問題は実行時に発生するため、原因の特定が難しくなっています。手順がエラーをスローするシナリオを再現できません。
私の理解では、98% のケースで問題なく両方の手順が実行されているため、無効な Open-Fetch-Close コマンドが原因であるとは考えられません。
例外がスローされる理由として考えられるものはありますか?
サンプルコードを追加しています:
CURSOR curWork(vCaseId VARCHAR2) IS
SELECT w.X_WORKFUNCTION_ID
FROM table_case c, table_queue w
WHERE c.id_number = vCaseId
AND c.CASE_CURRQ2QUEUE = w.objid;
CURSOR curPart(vCaseId VARCHAR2) IS
SELECT p.x_part_number, p.X_FAULT_CATEGORY, p.X_FORW_GRP_ID
FROM table_case c, table_mod_level m, table_x_part_forw_grp p, table_part_num n
WHERE c.id_number =vCaseId
AND c.CASE_PRT2PART_INFO =m.objid
And m.part_info2part_num=N.OBJID
AND N.S_PART_NUMBER=P.X_PART_NUMBER;
PROCEDURE UpdateAddressXY(vCaseId IN VARCHAR2, nStatus IN OUT NUMBER, vComment OUT VARCHAR2) IS
bContinue boolean;
nJobCode VARCHAR2(4);
cnt number;
CURSOR curAddress(vCaseId VARCHAR2) IS
select a.X_COORDINATE_X , a.X_COORDINATE_Y, A.X_XY_ORIGIN
from table_address a, table_case c
where C.ID_NUMBER =vCaseId
and a.objid =c.CASE2ADDRESS;
rAdd curAddress%ROWTYPE;
--Get Dok Details
CURSOR curDok(vCaseId VARCHAR2) IS
select dk.x_dok_card_type, dk.x_line_src from table_x_kat_dok dk, table_case c
where c.objid=DK.X_KAT_DOK2CASE
and c.id_number=vCaseId;
rDok curDok%ROWTYPE;
--Get Jobcode Details
CURSOR curJCode(vWorkFunction Number, nForwGrpId Number) IS
select x_code, x_code2, x_code3
from table_x_queue_jobcode
where X_WORKFUNCTION_ID=vWorkFunction
and X_FORW_GRP_ID=nForwGrpId;
rJCode curJCode%ROWTYPE;
rPart curPart%ROWTYPE;
rWork curWork%ROWTYPE;
BEGIN
bContinue := true;
-- get Part details
OPEN curPart(vCaseId);
FETCH curPart INTO rPart;
IF curPart%NOTFOUND THEN
CLOSE curPart;
bContinue := FALSE;
nStatus := CONST.cError;
vComment := 'Part Details Not Found | UpdateAddressXY';
END IF;
CLOSE curPart;
-- get Work details
OPEN curWork(vCaseId);
FETCH curWork INTO rWork;
IF curWork%NOTFOUND THEN
CLOSE curWork;
bContinue := FALSE;
nStatus := CONST.cError;
vComment := 'Work Details Not Found | UpdateAddressXY';
END IF;
CLOSE curWork;
-- get Addess details
OPEN curAddress(vCaseId);
FETCH curAddress INTO rAdd;
IF curAddress%NOTFOUND THEN
CLOSE curAddress;
bContinue := FALSE;
nStatus := CONST.cError;
vComment := 'Address Details Not Found | UpdateAddressXY';
END IF;
CLOSE curAddress;
--get Dok details
OPEN curDok(vCaseId);
FETCH curDok INTO rDok;
IF curDok%NOTFOUND THEN
CLOSE curDok;
bContinue := FALSE;
nStatus := CONST.cError;
vComment := 'Dok Details Not Found | UpdateAddressXY';
END IF;
CLOSE curDok;
--get Jobcode details
OPEN curJCode(rWork.X_WORKFUNCTION_ID,rPart.X_FORW_GRP_ID);
FETCH curJCode INTO rJCode;
IF curJCode%NOTFOUND THEN
CLOSE curJCode;
bContinue := FALSE;
nStatus := CONST.cError;
vComment := 'Jobcode Details Not Found | UpdateAddressXY';
END IF;
CLOSE curJCode;
if bContinue then
--job code
if ( Not (rDok.x_line_src is null OR rJCode.x_code3 is null OR upper(rDok.x_line_src)='DOK') ) then
nJobCode:= rJCode.x_code3;
elsif (rDok.x_dok_card_type is not null and rJCode.x_code2 is not null and ( substr(rDok.x_dok_card_type,1,1)='v' OR substr(rDok.x_dok_card_type,1,1)='V')) then
nJobCode:= rJCode.x_code2;
else
nJobCode:= rJCode.x_code;
End if;
select count(CASE_ID) into cnt from table_x_cu_address_jobcode where CASE_ID=vCaseId;
if cnt=0 then
Insert into table_x_cu_address_jobcode(CASE_ID, X_JOB_CODE, X_COORDINATE_X, X_COORDINATE_Y, X_XY_ORIGIN)
values(vCaseId,nJobCode,rAdd.X_COORDINATE_X,rAdd.X_COORDINATE_Y,rAdd.X_XY_ORIGIN);
else
Update table_x_cu_address_jobcode
set X_JOB_CODE=nJobCode,
X_COORDINATE_X=rAdd.X_COORDINATE_X,
X_COORDINATE_Y = rAdd.X_COORDINATE_Y,
X_XY_ORIGIN=rAdd.X_XY_ORIGIN
where CASE_ID=vCaseId;
end if;
END if;
EXCEPTION
WHEN OTHERS THEN
IF vErrorMsg IS NULL THEN
vErrorMsg := TO_CHAR(SQLCODE) || ' - ' || SQLERRM || cCRLF || ' | UpdateAddressXY';
ELSE
vErrorMsg := vErrorMsg || ' | UpdateAddressXY';
END IF;
nStatus := CONST.cError;
vComment := vErrorMsg;
insert into xxx(dat,seq,msg)
values(SYSDATE,71180,vComment ||'@' || DBMS_UTILITY.FORMAT_ERROR_STACK);
End;