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
 

 

Retrieve 10 rows 4m a TABLE which has 1000 rws using CURSOR?

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

New User


Joined: 03 Aug 2009
Posts: 25
Location: Singapore

PostPosted: Sun Oct 25, 2009 1:33 am    Post subject: Retrieve 10 rows 4m a TABLE which has 1000 rws using CURSOR?
Reply with quote

Hi Friends,
1. I want to retrieve 10 rows from a TABLE which has 1000 rows using CURSOR without fetching all the records(1000 rows)?
2. Consider a table has 'm' rows. I want to retrieve 'n' (n<m) rows where we will pass the value of 'n' dynamically? Is it possible to pass value to 'n' dynamically?
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sun Oct 25, 2009 3:11 am    Post subject:
Reply with quote

Hello,

1. FETCH the first 10 and then end the process. The other 990. will not be fetched.

2. Yes. You can pick the method to get the value into the program (parm, sysin, vsam file, database table, whatever).
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Sun Oct 25, 2009 3:24 am    Post subject:
Reply with quote

Here again, a little reading of an SQL Reference would probably help you.
FETCH FIRST
Back to top
View user's profile Send private message
ajeshrn

New User


Joined: 25 Mar 2009
Posts: 78
Location: India

PostPosted: Sun Oct 25, 2009 10:14 am    Post subject:
Reply with quote

Hi samimaktar,

Is your requirement like u should be able to fetch first n records dynamically.That means the value of n can vary from time to time?If thats what you are looking for then use a dynamic sql and move what ever value u want to the variable.Just a sample code.I have done this in my aplication program.It works:
Ex:

05 WS-VAR1 CHAR(50)
'SELECT * FROM A.TABLE1 FETCH FIRST'
05 WS-VALN CHAR(02)
05 WS-VAR1 CHAR(20)
'ROWS ONLY'.
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 Loading data to table gives wrong for... Raghu navaikulam DB2 19 Thu Jul 13, 2017 2:11 pm
No new posts compare 2 rows within the same file ram_vizag SYNCSORT 7 Wed Jun 14, 2017 12:34 am
No new posts Testing rerad cursor for status with ... John F Dutcher DB2 8 Fri May 19, 2017 9:35 pm
No new posts unload data from table with lob columns farhad_evan DB2 1 Sat Apr 22, 2017 1:32 pm
No new posts after TBSARG: Row 370 from 1000 Pedro TSO/ISPF 1 Fri Apr 14, 2017 2:32 am


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