Quantcast
Channel: IBM Mainframe Computers Forums
Viewing all articles
Browse latest Browse all 8500

DB2 :: RE: Updating Cursor row withour using FOR UPDATE

$
0
0
Author: RahulG31
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


.


Viewing all articles
Browse latest Browse all 8500

Trending Articles