该错误码详细描述如下: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.

解决方案 »

  1.   

    看你的程序,就是FETCH完游标记录后没有退出循环。
    FETCH ...
    INTO ...;
    EXIT WHEN ...%NOTFOUND;
    希望对你有帮助。
      

  2.   

    我后面有写:EXEC SQL CLOSE myCur3;
      

  3.   

    你应该立即在FETCH后检查SQLCODE状态,一旦没有记录(或者FETCH完)就要退出循环。
      

  4.   

    我也有加判断啊!
    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就退出了。
      

  5.   

    试着这样写:
    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;
      

  6.   

    表里数据的长度是不确定的,不能使用for循环啊。
      

  7.   

    有高手帮我看看吗?
    我现在已经发现:当我把select语句中的where条件查询去掉时,
    程序可以正常通过。不明白这是为什么?数据及其定义的大小都没问题。
      

  8.   

    呵呵,我来总结一下:
    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
    少了冒号,属于粗心的问题。
    可以结帖了。