View previous topic :: View next topic
|
Author |
Message |
bosalting
New User
Joined: 02 Jun 2007 Posts: 4 Location: Philippines
|
|
|
|
Hi everyone,
Im wondering, there's an impedance mismatch between set-level processing of DB2 and record-level processing of COBOL.. That's why we use CURSORs right? Would it be possible to UPDATE a table in one blow, affecting several rows in a program. If its possible, is it advisable resource-wise? A related reading material would be most appreciated.. |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
You don't need cursors to do updates to a table. The only time a cursor is needed is when reading multiple rows from a table. |
|
Back to top |
|
|
bosalting
New User
Joined: 02 Jun 2007 Posts: 4 Location: Philippines
|
|
|
|
Steve,
Yes you do need a CURSOR if you want to update a table with multiple rows. You UPDATE it one at a time. Thats why in the CURSOR declaration for an update, you use keywords FOR UPDATE OF... |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
But, if you do this
Code: |
EXEC SQL
UPDATE TABLE
SET COLUMN1 = SomeVal
END-EXEC
|
I have updated multiple rows without using a cursor.... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Yes you do need a CURSOR if you want to update a table with multiple rows. You UPDATE it one at a time |
No, you do not have to use a cursor to update multiple rows. You can update multiple (selected) rows in a table by specifying a WHERE and you can update every row in a table if you do not specify a WHERE.
You update one row at a time when you are updating a row that was read by a cursor. |
|
Back to top |
|
|
|