Problem solve Get help with specific problems with your technologies, process and projects.

Resolving the ORA-01002 error

I am working as an Oracle/VB programmer. I am trying to lock a record using "FOR UPDATE NOWAIT" statement. For example, when I open a recordset with

select * from emp where empno =1 for update nowait
I get the error:
ORA-01002: fetch out of sequence
This statement works fine if the record is already locked by some other user through other sessions. When the record is not locked, the above statement should lock the record. In this case it's giving the error. Please help me find the solution.

Here's the Oracle Error Messages guide description of this error:

In a host language program, a FETCH call was issued out of sequence. A successful parse-and-execute call must be issued before a fetch. This can occur if an attempt was made to FETCH from an active set after all records have been fetched. This may be caused by fetching from a SELECT FOR UPDATE cursor after a commit. A PL/SQL cursor loop implicitly does fetches and may also cause this error.
Since you're doing this from VB, the way it's being called may be the problem. Check your code for sequencing of steps.

For More Information

Dig Deeper on Oracle error messages