IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Db2 fetching again records which are updated


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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
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: 2481
Location: @my desk

PostPosted: Mon Jan 05, 2009 11:45 am
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
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Join multiple records using splice DFSORT/ICETOOL 5
Search our Forums:

Back to Top