ORA-01002: fetch out of sequence

当遇到ORA-01002错误时,通常是因为尝试从不再有效的游标中获取数据。可能的原因包括:1) 在已检索完所有行并返回ORA-1403错误后仍尝试获取;2) 在带有FOR UPDATE子句打开的游标中执行COMMIT;3) 重新绑定SQL语句中的占位符后,未重新执行就尝试获取。解决方案包括:1) 不要在检索完最后一行后尝试获取;2) 不要在FOR UPDATE游标的循环内执行COMMIT;3) 重新执行语句后再尝试获取。

ORA-01002: fetch out of sequence

错误定位:

SQL> !oerr ora 01002
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.

SQL>

查看pl sql:

declare
  cursor emp_cursor is
    select * from emp_text for update;
  v_object_name emp_text%rowtype;
begin
  open emp_cursor;
  loop
    fetch emp_cursor
      into v_object_name;
    if emp_cursor%found then
      update emp_text
         set object_id =
             (emp_seq.nextval)
       where object_name = v_object_name.object_name;
       COMMIT;
    end if;
    exit when emp_cursor%notfound;
  end loop;
  close emp_cursor;
 end;

正确写法:

declare
  cursor emp_cursor is
    select * from emp_text for update;
  v_object_name emp_text%rowtype;
begin
  open emp_cursor;
  loop
    fetch emp_cursor
      into v_object_name;
    if emp_cursor%found then
      update emp_text
         set object_id =
             (emp_seq.nextval)
       where object_name = v_object_name.object_name;
    end if;
    exit when emp_cursor%notfound;
  end loop;
  close emp_cursor;
  COMMIT;
end;



 

Couldn't get row from result set ORA-01002: fetch out of sequence at org.pentaho.di.core.database.Database.getRow(Database.java:2764) at org.pentaho.di.core.database.Database.getRow(Database.java:2734) at org.pentaho.di.trans.steps.tableinput.TableInput.processRow(TableInput.java:148) at org.pentaho.di.trans.step.RunThread.run(RunThread.java:62) at java.lang.Thread.run(Thread.java:748) Caused by: java.sql.SQLException: ORA-01002: fetch out of sequence at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:509) at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:461) at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1104) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:550) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:268) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:655) at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:229) at oracle.jdbc.driver.T4CStatement.fetch(T4CStatement.java:1037) at oracle.jdbc.driver.OracleStatement.fetchMoreRows(OracleStatement.java:3456) at oracle.jdbc.driver.InsensitiveScrollableResultSet.fetchMoreRows(InsensitiveScrollableResultSet.java:742) at oracle.jdbc.driver.InsensitiveScrollableResultSet.absoluteInternal(InsensitiveScrollableResultSet.java:698) at oracle.jdbc.driver.InsensitiveScrollableResultSet.next(InsensitiveScrollableResultSet.java:412) at org.pentaho.di.core.database.Database.getRow(Database.java:2752) ... 4 more Caused by: Error : 1002, Position : 0,, Sql = INSERT into ODS_DIS_DAILY_NEED_NETVAL (finprod_id , portfolio_val_type , confirm_date , val_date , check_result , whether_zero_share , whether_sync_send , create_user , create_dept , create_time , update_user , update_time ) select a.finprod_id , a.portfolio_val_type , a.confirm_date , a.val_date , a.check_result , a.whether_zero_share , a.whether_sync_send , a.create_user , a.create_dept , a.create_time , a.update_user , a.update_time from sylcsys.zcgl_mir_DAILY_NEED_NETVAL a where not exists (select 1 from ODS_DIS_DAILY_NEED_NETVAL b where a.finprod_id=b.finprod_id and a.val_date=b.val_date ), OriginalSql = INSERT into ODS_DIS_DAILY_NEED_NETVAL (finprod_id , portfolio_val_type , confirm_date , val_date , check_result , whether_zero_share , whether_sync_send , create_user , create_dept , create_time , update_user , update_time ) select a.finprod_id , a.portfolio_val_type , a.confirm_date , a.val_date , a.check_result , a.whether_zero_share , a.whether_sync_send , a.create_user , a.create_dept , a.create_time , a.update_user , a.update_time from sylcsys.zcgl_mir_DAILY_NEED_NETVAL a where not exists (select 1 from ODS_DIS_DAILY_NEED_NETVAL b where a.finprod_id=b.finprod_id and a.val_date=b.val_date ), Error Msg = ORA-01002: fetch out of sequence at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:513) ... 16 more
最新发布
11-05
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值