View previous topic :: View next topic |
Author |
Message |
anu.k Beginner
Joined: 09 Nov 2006 Posts: 6 Topics: 4
|
Posted: Tue May 12, 2009 3:41 am Post subject: Query on DB2 cursor |
|
|
Hi,
In my application program, I have declared a cursor with some 'where' clause for table X. For each Fetch from the cursor, I am 'inserting' a new row into the table X which also satisfies the 'where' clause.
My question is, somehow these newly inserted rows are seeping back into the cursor and are being fetched again. I am not sure of the reason.
Please advice on why this is happening and ways to overcome it.
Thanks
Anu |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Tue May 12, 2009 5:16 am Post subject: |
|
|
before SENSITIVE Cursors where available,
we could normally get around this
by having a WHERE Condition in the DECLARE CURSOR
that would not be satisfied by the new INSERTs; normally a date.
Knowing that this would occur,
I have always been able to avoid it,
thus never complicated my SQL with Scrollable/Sensitive cursors.
Read up on these types of Cursors, they were introduced to easily solve this type of problem. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
vini Intermediate
Joined: 12 Jan 2004 Posts: 240 Topics: 48 Location: Maryland
|
Posted: Mon May 18, 2009 2:26 pm Post subject: |
|
|
When you INSERT do you have a column correspoding to Current date for ex: a Creation date ?
If yes, you can change your WHERE clause to exclude these rows
For ex:
WHERE...
......
AND CREATION_DATE < :WSH-CURRENT-DATE |
|
Back to top |
|
 |
kalidasv Beginner
Joined: 05 Mar 2009 Posts: 13 Topics: 8
|
Posted: Wed May 20, 2009 4:35 pm Post subject: Query on DB2 Cursor |
|
|
This is interesting.
Are you executing the 'OPEN CURSOR' statement multiple times.
My understanding/experience is once the 'OPEN CURSOR' statement is executed, newly inserted rows should not cause any difference. Only when the CURSOR is closed and opened again, the rows inserted would be fetched.
Database gurus, please help. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12380 Topics: 75 Location: San Jose
|
Posted: Wed May 20, 2009 4:45 pm Post subject: Re: Query on DB2 Cursor |
|
|
kalidasv wrote: | My understanding/experience is once the 'OPEN CURSOR' statement is executed, newly inserted rows should not cause any difference. Only when the CURSOR is closed and opened again, the rows inserted would be fetched.
Database gurus, please help. |
Nope , Your understanding is wrong. Read this how DB2 processes a cursor and the effects of a temporary copy of a result table |
|
Back to top |
|
 |
|
|