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 nowaitI get the error:
ORA-01002: fetch out of sequenceThis 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
- Dozens more answers to tough Oracle questions from Karen Morton are available.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our applications, PL/SQL, database administration and data warehousing gurus are waiting to answer your toughest questions.