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
 

 

Multiple Cursors

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Ananya

New User


Joined: 26 Feb 2004
Posts: 19
Location: Chennai

PostPosted: Thu Mar 04, 2004 10:40 am    Post subject: Multiple Cursors
Reply with quote

Dear All!!!

1. How do you use MULTIPLE CURSORS for a single table?

Imagine a scenario like this ...
A Result Set has 30 Rows returning to the application program. Now I want these things to happen.... (Open Multiple Cursors)

a. FIRST CURSOR should fetch first 10 rows.
b. SECOND CURSOR should fetch then next 10 rows (i.e., 11 - 20)
c. THIRD CURSOR should fetch the last 10 rows (21 - 30)

Now my question is how do I point to different locations in the Result Set with 3 different Cursors???

I'm not sure if this is really possible.

Pls do help me.

Views are appreciated.
Thanks in advance!!

Cheers
-Ananya
Back to top
View user's profile Send private message

mdtendulkar

Active User


Joined: 29 Jul 2003
Posts: 238
Location: USA

PostPosted: Fri Mar 19, 2004 11:39 am    Post subject:
Reply with quote

Hello Ananya,

Your requirement is non-standard. As per normal processing this can not be done.

Following are the ways to do it:

1) You can use only one cursor and process the specific number of records in paragraphs. say 1 to 15 in Para-1, 16-30 in Para-2 and remaining 15 records in Para-3.

In this way you can direct the processing in your desired manner.

2) The other way to do is as below:

Quote:


a) Get the number of records from the table for the query.
SELECT COUNT(*) FROM <TABLE-NAME> WHERE <WHERE-CONDITION>

b) Divide the count by 3 and get the integer records

c) In first Cursor by using FETCH FIRST N ROWS clause fetch the COUNT/3 records in ASCENDING order

d) In third Cursor by using FETCH FIRST N ROWS clause fetch the COUNT/3 records in DESCENDING order
(Here the last record will come first and first record will come last)

e) Now that you have first N/3 and last N/3 records there will be middle N/3 records remaining. These records can be retrieved by using the LAST KEY of both the cursors. (Last record's KEY of both the cursors)

SELECT * FROM <TABLE-NAME> WHERE KEY > KEY1 and KEY < KEY3

Here KEY1 = Last record of the first cursor.
KEY3 = Last record of third cursor.



I have not tried this solution, but you can try this out.

Hope this helps,

Regards
Mayuresh Tendulkar
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 Changeman get multiple "Browse C... elixir1986 Compuware & Other Tools 4 Fri Jul 14, 2017 1:48 am
No new posts How to write Specific Fields from Mul... Padhu SYNCSORT 6 Thu Jul 06, 2017 10:26 am
No new posts Unable to create multiple files using... mbattu COBOL Programming 3 Fri May 05, 2017 5:35 pm
This topic is locked: you cannot edit posts or make replies. SDSF multiple spool datasets extracte... PJAlarcon CLIST & REXX 1 Fri Apr 21, 2017 10:50 pm
No new posts Validating file with multiple header/... mohitsaini DFSORT/ICETOOL 6 Thu Apr 13, 2017 1:53 am


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