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: 19243
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: 6965
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 All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts count contained values of several col... DB2 5
No new posts To join 2 tables and to join 3rd tabl... DB2 8
No new posts Create a specific record/file based o... SYNCSORT 8
No new posts Extract ISPF table column headings CLIST & REXX 2
No new posts Reflection 3270 screen shows only 23 ... Compuware & Other Tools 6
Search our Forums:


Back to Top