Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Db2 fetching again records which are updated

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
harijax

New User


Joined: 16 Jul 2008
Posts: 22
Location: Bangalore

PostPosted: Wed Dec 24, 2008 8:54 am    Post subject: Db2 fetching again records which are updated
Reply with quote

Hi,

I have a DECLARE cursor on a tble like below.
NAME MARKS VERSION_NO
--------------------------------
AA 45 1
BB 42 2
CC 43 1

I am fetching these records, and updating the marks field. I also increment the VERSION_NO field after each update.

Problem: After I fetch the first record (AA) and updates the marks, the updated record is fetched again. But strangley this happens only once. I mean the third fetch is my actual 2nd record (BB).


Regards
JK
Back to top
View user's profile Send private message

ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Dec 24, 2008 3:36 pm    Post subject:
Reply with quote

What is your cursor declaration?
Back to top
View user's profile Send private message
harijax

New User


Joined: 16 Jul 2008
Posts: 22
Location: Bangalore

PostPosted: Mon Jan 05, 2009 11:15 am    Post subject:
Reply with quote

I have a join query as

DECLARE CURSOR
SELECT NAME, MARKS
FROM MARKS A, STUDENT B
WHERE A.NAME = B.NAME
AND A.MARKS > 40.


I have an update as below.
UPDATE MARKS SET MARKS = :NEW-marks,
VERSON_NO = VERSIOn_NO + 1
WHERE NAME = :ws-Name
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2181
Location: @my desk

PostPosted: Mon Jan 05, 2009 11:45 am    Post subject:
Reply with quote

Quote:
I mean the third fetch is my actual 2nd record (BB)
Do you have an ORDER BY NAME clause in your DECLARE CURSOR statement?
Back to top
View user's profile Send private message
harijax

New User


Joined: 16 Jul 2008
Posts: 22
Location: Bangalore

PostPosted: Mon Jan 05, 2009 12:19 pm    Post subject:
Reply with quote

Yes.. i have an ORDER BY NAME.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Jan 06, 2009 3:33 pm    Post subject:
Reply with quote

are you sure there is 2nd occurence of the same name ? try using FOR UPDATE cursor....
Back to top
View user's profile Send private message
harijax

New User


Joined: 16 Jul 2008
Posts: 22
Location: Bangalore

PostPosted: Tue Jan 06, 2009 3:42 pm    Post subject:
Reply with quote

Hi Ashimer,

It is a join query first of all. I think FOR UPDATE wont work there.

It is picking.

I followed the below method.

ORDER BY NAME, VERSION_NO DESC.

So after I updated VERSIOn_NO, the updated record was not fetched again.

But my clients ay it is not a good method.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Jan 06, 2009 3:48 pm    Post subject:
Reply with quote

Yes you are right .... i overlooked that part ....
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jan 06, 2009 3:53 pm    Post subject:
Reply with quote

why do you need the student table in the join?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 8 Fri Dec 09, 2016 4:40 am
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts abend sort based on count records in ... anatol DFSORT/ICETOOL 5 Mon Oct 17, 2016 10:10 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us