结果一样:fetch out of sequence

解决方案 »

  1.   

    语句很简单,肯定没有问题,单独在SQL PLUS下执行可以通过。序列也没超出,
      

  2.   

    ORA-01002: fetch out of sequence 
    Cause: In a host language program, a FETCH call was issued out of sequence. A successful parse-and-execute call must be issued before a fetch. This can occur if an attempt was made to FETCH from an active set after all records have been fetched. This may be caused by fetching from a SELECT FOR UPDATE cursor after a commit. A PL/SQL cursor loop implicitly does fetches and may also cause this error. Action: Parse and execute a SQL statement before attempting to fetch the data. 
      

  3.   

    我碰到过类似的问题,在fetch的过程中如果有commit就会出错。
    下面这个例子供你参考:
    void main()
    {
      EXEC SQL BEGIN DECLARE SECTION;
      char   *uid= "qhdcrd/qhdcrd@ora9";
      int     empnum;
      varchar rowident[ 30 ];
      EXEC SQL END DECLARE SECTION;  EXEC SQL WHENEVER SQLERROR DO sqlerr( );
      EXEC SQL CONNECT :uid;
      printf( "\nConnected to ORACLE\n" );  EXEC SQL DECLARE c1 CURSOR FOR
        SELECT rowid, empno FROM ora1002tab;
      EXEC SQL OPEN c1;  EXEC SQL WHENEVER NOT FOUND DO break;
      while( 1 == 1 )
      {
        EXEC SQL FETCH c1 INTO :rowident, :empnum;
        EXEC SQL UPDATE ora1002tab SET empno = :empnum + 50
          WHERE rowid = :rowident;
        if( sqlca.sqlcode )
         printf( " attention here : fail - [%ld] ", sqlca.sqlcode ) ;
        EXEC SQL COMMIT;
      } /* end while */  EXEC SQL CLOSE c1;
      EXEC SQL COMMIT WORK RELEASE; /* logoff database */
      exit(0);
    } /* end main( ) */
    void sqlerr( void )
    {
      EXEC SQL WHENEVER SQLERROR CONTINUE;  printf("\nORACLE error detected:\n");
      printf("\n% .70s \n", sqlca.sqlerrm.sqlerrmc);  EXEC SQL ROLLBACK RELEASE;
      exit(1);
    } /* end sqlerr( ) */但如果你没用oracle的commit而用了其他方式提交事物,这个办法可能不行了。
      

  4.   

    Thanks for your attention!