View previous topic :: View next topic
|
Author |
Message |
harijax
New User
Joined: 16 Jul 2008 Posts: 22 Location: Bangalore
|
|
|
|
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 |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
What is your cursor declaration? |
|
Back to top |
|
|
harijax
New User
Joined: 16 Jul 2008 Posts: 22 Location: Bangalore
|
|
|
|
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 |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
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 |
|
|
harijax
New User
Joined: 16 Jul 2008 Posts: 22 Location: Bangalore
|
|
|
|
Yes.. i have an ORDER BY NAME. |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
are you sure there is 2nd occurence of the same name ? try using FOR UPDATE cursor.... |
|
Back to top |
|
|
harijax
New User
Joined: 16 Jul 2008 Posts: 22 Location: Bangalore
|
|
|
|
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 |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
Yes you are right .... i overlooked that part .... |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
why do you need the student table in the join? |
|
Back to top |
|
|
|