重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 23|回复: 0
打印 上一主题 下一主题

[Oracle] ORA-01002: fetch out of sequence

[复制链接]
跳转到指定楼层
楼主
发表于 昨天 13:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
现象:
ORA-01002: 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.

## ORA-01002: fetch out of sequence

ORA-01002: fetch out of sequence 是Oracle数据库中一个通用的错误代码,该错误表明当前操作被中断,因为在令一个非法的fetch操作中,应用程序试图从数据库中检索一行数据,而不是应该先执行的open操作。

原因:
这个错误的常见原因是在一个PL/SQL块中,用户在执行FETCH操作之前没有先执行OPEN操作,或者在CUrsor上执行了两次OPEN操作。 这会导致游标已经关闭,结果在执行FETCH之前,不能获取打开游标,从而导致ORA-10002: fetch out of sequence 错误消息出现。

处理方法:
1.确定错误发生的PL/SQL块;

2.检查错误发生处,看是否在FETCH操作之前确实存在OPEN操作;

3.如果存在游标未关闭的情况,实施相应的函数,如 CLOSE CURSOR 等操作将之前的游标关闭;

4.重新编译PL/SQL语句块,重新执行。

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-9-24 00:31 , Processed in 0.111319 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表