MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Query on DB2 cursor

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
anu.k
Beginner


Joined: 09 Nov 2006
Posts: 6
Topics: 4

PostPosted: Tue May 12, 2009 3:41 am    Post subject: Query on DB2 cursor Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Tue May 12, 2009 5:16 am    Post subject: Reply with quote

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
View user's profile Send private message
vini
Intermediate


Joined: 12 Jan 2004
Posts: 240
Topics: 48
Location: Maryland

PostPosted: Mon May 18, 2009 2:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
kalidasv
Beginner


Joined: 05 Mar 2009
Posts: 13
Topics: 8

PostPosted: Wed May 20, 2009 4:35 pm    Post subject: Query on DB2 Cursor Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12380
Topics: 75
Location: San Jose

PostPosted: Wed May 20, 2009 4:45 pm    Post subject: Re: Query on DB2 Cursor Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group