MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Select from delete when deleting multiple rows

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
jim haire
Beginner


Joined: 30 Dec 2002
Posts: 140
Topics: 40

PostPosted: Fri Apr 06, 2012 12:15 pm    Post subject: Select from delete when deleting multiple rows Reply with quote

With version 9 of DB2 there is a new capability to do a SELECT statement to get the rows which are being deleted.

I have an application where I have multiple rows being deleted and want to return certain columns for all the rows that were deleted. I am doing this in COBOL. However, there are not any good examples of how this can be done online or in the programming manuals.

I have set up my host variables as arrays:
Code:

01  DELETED-ROWS.
      05  DELETED-ROW-VARIABLES.
            10  HOST-VARIABLE-1      PIC S9(4)     COMP  OCCURS 9999 TIMES.
            10  HOST-VARIABLE-2      PIC X(10)     OCCURS 9999 TIMES.


Since it is a single delete (deleting multiple rows), can I code the SELECT in this way:
Code:

SELECT INTO :host-variable-1, :host-variable-2 FROM OLD TABLE
(DELETE FROM TABLE  WHERE HOST-VARIABLE-2 < CURRENT DATE)


or because I am returning multiple rows from the SELECT, do I have to define a cursor for the rows being returned?

Code:

DECLARE DEL_CURS CURSOR FOR   
   SELECT INTO :host-variable-1, :host-variable-2 FROM OLD TABLE
   (DELETE FROM TABLE  WHERE HOST-VARIABLE-2 < CURRENT DATE)


After this I did a Single OPEN, FETCH, and CLOSE of the cursor.

After testing both methods, I got exactly the same results. All the records meeting the criteria were deleted, but only the first positions in the array contained values.
(Examples: HOST-VARIABLE-1 (1), HOST-VARIABLE-2 (1) ).

Is it possible to do what I'm doing and get all the deleted values loaded into the array? What am I missing?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Fri Apr 06, 2012 12:53 pm    Post subject: Reply with quote

jim haire,

Take a look at this Kewl DB2 for z/OS Version 8 Feature Part 2a: Multi-row INSERT & FETCH

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jim haire
Beginner


Joined: 30 Dec 2002
Posts: 140
Topics: 40

PostPosted: Fri Apr 06, 2012 1:21 pm    Post subject: Reply with quote

Thanks for pointing me to my problem

I didn't have the NEXT ROWSET and number of rows to fetch on my FETCH statement. Embarassed

I appreciate the help!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group