title: How to resolve fetch out of sequence in oracle?
body: <p>I have a procedure in which I am often getting the following error in oracle 11g:</p>
  
  <pre><code>ORA-01002: fetch out of sequence ORA-06512: 
  at "LEAVE.GES_ERP_LEV_FFS_INTERFACE_PRC", line 350 ORA-06512: at line 1.
  </code></pre>
  
  <p>at line 350 I have-</p>
  
  <pre><code>BEGIN
  
    FOR V_INTERFACE_EMP IN CUR_INTERFACE_EMP LOOP        (Line 350)
        EXIT WHEN CUR_INTERFACE_EMP%NOTFOUND;
        V_ERR_FLAG  := 'N';
        V_LOCAL_EMP := 'Y';
  
        BEGIN
  </code></pre>
  
  <p>The Cursor CUR_INTERFACE_EMP is declared as below</p>
  
  <pre><code>SELECT GELF.*
     FROM GES_ERP_LEV_FFS_INTERFACE_T GELF
   WHERE (GELF.BALANCE_FLAG != 'W' 
           OR GELF.CASE_FLAG = 'S' 
           OR SELF.BALANCE_FLAG IS NULL)
      AND GELF.PROCESS_FLAG = 'N'
      AND GELF.DATE_OF_RELEASE &lt;= TRUNC(SYSDATE);
  </code></pre>
  
  <p>If i update some records of the table with Process_Flag Y,the batch works fine for some time and then again after some days we get this same issue.</p>
  
  <p>Please help,let me know in case data is also needed for the mentioned table.</p>