IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

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


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Sun Oct 25, 2009 3:11 am
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: 6966
Location: porcelain throne

PostPosted: Sun Oct 25, 2009 3:24 am
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top