当前位置:  数据库>oracle

ORA-01002: fetch out of sequence

    来源: 互联网  发布时间:2017-06-02

    本文导语: 错误定位: 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 err...

错误定位:
 
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;


    
 
 

您可能感兴趣的文章:

 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • 出现ORA-01401和ORA-01008错误?
  • Eclipse连接Oracle数据库的ORA-00604 ORA-12705错误
  • oracle ORA-01114、ORA-27067错误解决方法
  • Oracle不能删除表 ORA-00604 ORA-01422 错误
  • 如何得到带有ora的行的下一行
  • ORA-12514及ORA-28547错误解决方案
  • 如何配置 linux 下 oracle 的 listener .ora 和
  • 浅析如何在tnsnames.ora中配置监听
  • Orcle的package中访问其它Schema的表报错ORA-00942解决方法
  • oracle远程连接服务器出现 ORA-12170 TNS:连接超时 解决办法
  • [Oracle] 浅析令人抓狂的ORA-01555问题
  • 解决报错ora-32035的方法分析
  • aq.executeQuery: ORA-00020: maximum number of processes (59) exceeded
  • Oracle 数据库闪回功能设置出现ORA-19809和ORA-19804错误
  • ORA-00947:Not enough values (没有足够的值)的深入分析
  • solaris10 安装 ora9.2.0.1 时报错
  • 在UNIX下,我的ORA817该怎么样才可以自己启动呀?
  • 基于ORA-12170 TNS 连接超时解决办法详解
  • plsql连接oracle数据库报ora 12154错误解决方法
  • 安装oracle出现error:ora-01031:insufficient privilleges的解决


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,