Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
i want to fetch first 5 rows and last 5 rows in a table?

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

New User


Joined: 11 Apr 2006
Posts: 93

PostPosted: Tue Nov 21, 2006 11:50 am    Post subject: i want to fetch first 5 rows and last 5 rows in a table?
Reply with quote

I have table that contain 50 rows,My requirement is i want fetch first 5 rows and last 5 rows in the table?
Back to top
View user's profile Send private message

MFRASHEED

Active User


Joined: 14 Jun 2005
Posts: 186
Location: USA

PostPosted: Tue Nov 21, 2006 9:21 pm    Post subject: Re: i want to fetch first 5 rows and last 5 rows in a table?
Reply with quote

Try using CURSOR and FETCH options

refer to

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/dsnsqj10/5.57?ACTION=MATCHES&REQUEST=fetch&TYPE=FUZZY&SHELF=&DT=20040216135741&CASE=&searchTopic=TOPIC&searchText=TEXT&searchIndex=INDEX&rank=RANK&ScrollTOP=FIRSTHIT#FIRSTHIT

Look for options like:

Code:

FETCH FIRST ROWSET FOR 5     | Cursor is positioned on a rowset of   
ROWS                         | size 5, consisting of rows 1, 2, 3, 4,
                             | and 5.                                 


Code:

+------------------------------+-----------------------------------------|
| FETCH LAST ROWSET FOR 2 ROWS | Cursor is positioned on a rowset of     |
|                              | size 2, consisting of rows 14 and 15.   |

FETCH ROWSET STARTING AT     | Cursor is positioned on a rowset of   
ABSOLUTE 2 FOR 3 ROWS        | size 3, consisting of rows 2, 3, and 4.

Back to top
View user's profile Send private message
chettiyar
Currently Banned

New User


Joined: 27 Sep 2006
Posts: 6
Location: india,kerala

PostPosted: Wed Nov 22, 2006 12:24 pm    Post subject: where i need to give this fetch statement
Reply with quote

hi,
Thank u very much for porviding a good knowledge sharing topic.
Whether i need to specify these statements inside the declare cursor statement or any where else................................

special thanks to MFRASHEED
Back to top
View user's profile Send private message
MFRASHEED

Active User


Joined: 14 Jun 2005
Posts: 186
Location: USA

PostPosted: Wed Nov 22, 2006 11:23 pm    Post subject: Re: i want to fetch first 5 rows and last 5 rows in a table?
Reply with quote

You would need to first declare CURSOR with 'WITH ROWSET POSITIONING'.

Refer to http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/dsnsqj10/5.42?ACTION=MATCHES&REQUEST=CURSOR&TYPE=FUZZY&SHELF=&DT=20040216135741&CASE=&searchTopic=TOPIC&searchText=TEXT&searchIndex=INDEX&rank=RANK&ScrollTOP=FIRSTHIT#FIRSTHIT

and other statements to limit row selection will be part of actual FETCH statement. In earlier link i provided, page to then end and there are some good examples of FETCH.

I am glad i was able to help.
Back to top
View user's profile Send private message
babu_hi

New User


Joined: 11 Apr 2006
Posts: 93

PostPosted: Thu Nov 23, 2006 10:21 am    Post subject:
Reply with quote

Hi MFRASHEED,

Thanks for ur reply. i have executed this query it's working fine.

Regards
Babu
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 Fetch Previous month & year in MM... girishb2 DFSORT/ICETOOL 3 Thu Sep 21, 2017 9:54 pm
No new posts Conditional highlighting of rows in I... packerm CLIST & REXX 2 Thu Sep 21, 2017 6:50 pm
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
No new posts how to see when the last read access ... Mike 1304 DB2 1 Tue Sep 12, 2017 7:52 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us