View previous topic :: View next topic
|
Author |
Message |
anu2 Warnings : 1 New User
Joined: 10 Jun 2007 Posts: 36 Location: Chennai
|
|
|
|
Hi,
Please update me on the Update statement used in DB2.
How many types of Update we have ? Please let me know about the Update while using Cursors, say if Cursor is at 20th record and i want to update from 20th to 30th record and the second case till the last record.
Regards,
anu |
|
Back to top |
|
|
logeswarank Warnings : 1 New User
Joined: 15 Oct 2006 Posts: 22 Location: Chennai
|
|
|
|
Hi Anu,
Fetch the cursor in 20th position then continue to update the records.Please give me some example "what you are expecting?".
When your using the Cursor you should put the update staement in loop. |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi Anu,
One way to do this is to declare a cursor using update of & every time you fetched the record increase the counter & when counter >20 use
update where current of query to update the record
Code: |
DECLARE cursor_name FOR
SELECT *
FROM table_name
WHERE .....
FOR UPDATE OF column_name |
Code: |
EXEC SQL
OPEN cursor_name;
END-EXEC |
Code: |
EXEC SQL
FETCH FROM cursor_name
INTO ..........;
END-EXEC
EVALUATE SQLCODE
WHEN 0
ADD 1 TO WS-FLAG
WHEN +100
....
END-EVALUATE
IF WS-FLAG >20
PERFORM UPDATE-CURSOR
END-IF. |
Code: |
UPDATE-CURSOR.
EXEC SQL
UPDATE table_name
SET coloumn_name = ..
WHERE CURRENT OF cursor_name |
END-EXEC
This is not optimized solution but one way to achieve the desired result |
|
Back to top |
|
|
anu2 Warnings : 1 New User
Joined: 10 Jun 2007 Posts: 36 Location: Chennai
|
|
|
|
Thank you. |
|
Back to top |
|
|
|