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

Types of Update statements in DB2


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
anu2
Warnings : 1

New User


Joined: 10 Jun 2007
Posts: 36
Location: Chennai

PostPosted: Tue Sep 04, 2007 11:04 am
Reply with quote

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
View user's profile Send private message
logeswarank
Warnings : 1

New User


Joined: 15 Oct 2006
Posts: 22
Location: Chennai

PostPosted: Tue Sep 04, 2007 12:41 pm
Reply with quote

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

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Tue Sep 04, 2007 5:46 pm
Reply with quote

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
View user's profile Send private message
anu2
Warnings : 1

New User


Joined: 10 Jun 2007
Posts: 36
Location: Chennai

PostPosted: Wed Sep 05, 2007 1:26 pm
Reply with quote

Thank you.
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 Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Read a flat file and update DB2 table JCL & VSAM 2
No new posts how to update an ISR appl var from an... TSO/ISPF 8
No new posts Relate COBOL statements to EGL statement All Other Mainframe Topics 0
No new posts DB2 SQL query to read and update data... DB2 12
Search our Forums:

Back to Top