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 Searching a table for the field name? socker_dad COBOL Programming 8 Sat Mar 31, 2018 2:57 am
No new posts Need inputs on DB2 tablespace/table r... ashek15 DB2 3 Sat Mar 24, 2018 11:49 pm
No new posts help to replace columns by rows Vikas Maharnawar DFSORT/ICETOOL 8 Tue Mar 06, 2018 3:27 pm
No new posts COBOL declaration for table Poha Eater DB2 3 Mon Feb 26, 2018 6:58 pm
No new posts Logic to skip Maximum time-stamp and ... vickey_dw DB2 2 Thu Feb 01, 2018 11:15 pm

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