该错误码详细描述如下:01002, 00000, "fetch out of sequence"
// *Cause: This error means that a fetch has been attempted from a cursor
// which is no longer valid. Note that a PL/SQL cursor loop
// implicitly does fetches, and thus may also cause this error.
// There are a number of possible causes for this error, including:
// 1) Fetching from a cursor after the last row has been retrieved
// and the ORA-1403 error returned.
// 2) If the cursor has been opened with the FOR UPDATE clause,
// fetching after a COMMIT has been issued will return the error.
// 3) Rebinding any placeholders in the SQL statement, then issuing
// a fetch before reexecuting the statement.
// *Action: 1) Do not issue a fetch statement after the last row has been
// retrieved - there are no more rows to fetch.
// 2) Do not issue a COMMIT inside a fetch loop for a cursor
// that has been opened FOR UPDATE.
// 3) Reexecute the statement after rebinding, then attempt to
// fetch again.
// *Cause: This error means that a fetch has been attempted from a cursor
// which is no longer valid. Note that a PL/SQL cursor loop
// implicitly does fetches, and thus may also cause this error.
// There are a number of possible causes for this error, including:
// 1) Fetching from a cursor after the last row has been retrieved
// and the ORA-1403 error returned.
// 2) If the cursor has been opened with the FOR UPDATE clause,
// fetching after a COMMIT has been issued will return the error.
// 3) Rebinding any placeholders in the SQL statement, then issuing
// a fetch before reexecuting the statement.
// *Action: 1) Do not issue a fetch statement after the last row has been
// retrieved - there are no more rows to fetch.
// 2) Do not issue a COMMIT inside a fetch loop for a cursor
// that has been opened FOR UPDATE.
// 3) Reexecute the statement after rebinding, then attempt to
// fetch again.
FETCH ...
INTO ...;
EXIT WHEN ...%NOTFOUND;
希望对你有帮助。
EXEC SQL DECLARE myCur3 CURSOR FOR SELECT MYDATE,WTSJ,HTXH,GDDM
FROM CT_ORDER WHERE SCDM = :selwtcx_scdm and GDDM = :selwtcx_gddm and KHDM = selwtcx_khdm ORDER BY gddm;
EXEC SQL OPEN myCur3;
EXEC SQL FETCH myCur3 INTO :selwtcx_mydate,:selwtcx_wtsj,:selwtcx_htxh,:selwtcx_gddm;
userlog("sqlcode:%d",SQLCODE);
if (SQLCODE != 0)
break;
else
…………………
EXEC SQL CLOSE myCur3;(IF语句完了后)结果SQLCODE不为0就退出了。
EXEC SQL DECLARE myCur3 CURSOR FOR
SELECT MYDATE,WTSJ,HTXH,GDDM
FROM CT_ORDER
WHERE SCDM = :selwtcx_scdm and GDDM = :selwtcx_gddm and
KHDM = selwtcx_khdm ORDER BY gddm; EXEC SQL OPEN myCur3;
for (; ;) {
EXEC SQL FETCH myCur3 INTO
:selwtcx_mydate,:selwtcx_wtsj,:selwtcx_htxh,:selwtcx_gddm;
if (sqlca.sqlcode == 1403)
break;
......
}
EXEC SQL CLOSE myCur3;
我现在已经发现:当我把select语句中的where条件查询去掉时,
程序可以正常通过。不明白这是为什么?数据及其定义的大小都没问题。
EXEC SQL DECLARE myCur3 CURSOR FOR
SELECT MYDATE,WTSJ,HTXH,GDDM
FROM CT_ORDER
WHERE SCDM = :selwtcx_scdm and GDDM = :selwtcx_gddm and
KHDM = selwtcx_khdm ORDER BY gddm;
----------------------------------EXEC SQL OPEN myCur3;KHDM =: selwtcx_khdm ORDER BY gddm
少了冒号,属于粗心的问题。
可以结帖了。