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
 

 

Types of Update statements in DB2

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Types of Update statements in DB2
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    Post subject: Update Statement
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: 1187
Location: Bangalore,India

PostPosted: Tue Sep 04, 2007 5:46 pm    Post subject:
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    Post subject: Reply to: Types of Update statements in DB2
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    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 Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts -913/-911 Deadlock during UPDATE stat... NoSleep319 DB2 5 Fri Nov 18, 2016 12:37 am
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm


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