Author: RahulG31
Subject: Reply to: Updating Cursor row withour using FOR UPDATE
Posted: Thu Nov 10, 2016 9:36 pm (GMT 5.5)
chandan.inst, I don't see anything about impacting the WHERE clause in that link (may be I missed something). But, look at your cursor, it says WHERE COL3='ABC'.
And then you update (what you update is less relevant) using, again, WHERE COL3='ABC'.
and that creates an opportunity to have a pseudo (if I can call that) extra row to be created.
So, your cursor thinks it has 2 rows:
Now, when do you a next fetch it fetches second row i.e. COL1 as 'DEF'.
So, cursor is not repositioning the pointer, it is the extra row (that's what my understanding is).
To validate, add an Order by clause in your cursor i.e. ORDER BY COL1 ASC
When you have a cursor ordered by COL1 ASC , that would mean that the DEF row will be before XYZ and then you'll Not get anything on second fetch. i.e.
.
Subject: Reply to: Updating Cursor row withour using FOR UPDATE
Posted: Thu Nov 10, 2016 9:36 pm (GMT 5.5)
Quote: |
it says updates are impacting the WHERE clause and for that case explanation holds correct. |
chandan.inst, I don't see anything about impacting the WHERE clause in that link (may be I missed something). But, look at your cursor, it says WHERE COL3='ABC'.
And then you update (what you update is less relevant) using, again, WHERE COL3='ABC'.
and that creates an opportunity to have a pseudo (if I can call that) extra row to be created.
So, your cursor thinks it has 2 rows:
Code: |
COL1 COL3 XYZ ABC <-- This is already processed and cursor pointer at this row DEF ABC |
Now, when do you a next fetch it fetches second row i.e. COL1 as 'DEF'.
So, cursor is not repositioning the pointer, it is the extra row (that's what my understanding is).
To validate, add an Order by clause in your cursor i.e. ORDER BY COL1 ASC
When you have a cursor ordered by COL1 ASC , that would mean that the DEF row will be before XYZ and then you'll Not get anything on second fetch. i.e.
Code: |
COL1 COL3 DEF ABC XYZ ABC <-- You are already here and No more rows left for fetch |
.