ORA-01002: fetch out of sequence

不打扰是莪最后的温柔 提交于 2020-01-15 12:09:18

问题


I am getting org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL

UPDATE responses 
SET    version_no = ( version_no + 1 ), 
       read_status = 0, 
       tslastmodified = SYSDATE 
WHERE  responseid IN (SELECT responseid 
                      FROM   responses 
                      WHERE  read_status = 1 
                             AND tslastmodified < SYSDATE - 45 / ( 24 * 60 ) 
                             AND id IN (SELECT id 
                                        FROM   emp)) 

; SQL state [24000]; error code [1002]; ORA-01002: fetch out of sequence ; nested exception is java.sql.SQLException: ORA-01002: fetch out of sequence

JAVA code :

getJdbcTemplate().queryForObject(SurveyQuery.UPDATE_INPROCESS, Integer.class);

Please let me know what is wrong in above query


回答1:


You can modify your UPDATE statement to something like below

UPDATE RESPONSES SET VERSION_NO=(VERSION_NO+1), 
READ_STATUS=0, 
TSLASTMODIFIED = SYSDATE 
WHERE READ_STATUS = 1 
AND TSLASTMODIFIED < SYSDATE - 45/(24*60) 
AND EXISTS (SELECT 1 FROM EMP
            WHERE RESPONSES.ID = EMP.ID)

Note: Though you can use the above modified query but I doubt the said error is because of the posted update statement. From Documentation it looks like the cause of the above error could be

When you perform a FETCH on an active cursor after all records have been fetched.

(OR)

When you perform a FETCH on a SELECT FOR UPDATE after a COMMIT has been issued.



来源:https://stackoverflow.com/questions/26707896/ora-01002-fetch-out-of-sequence

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!