Retrieval of particular row in table



IBM's flagship relational database management system

Retrieval of particular row in table

Postby ronmathew » Mon Jan 14, 2008 4:19 pm

hi..

How can we retrieve a particular row,(for example the 55 th row from 100 rows ) using cursors in DB2.

If anyone knows this please answer...
ronmathew
 
Posts: 6
Joined: Mon Jan 14, 2008 3:51 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Retrieval of particular row in table

 

Re: Retrieval of particular row in table

Postby dick scherrer » Wed Jan 16, 2008 1:57 am

Hello,

for example the 55 th row from 100 rows
There is no 55th row in a table. . . . Tables do not "work that way".

If you want to decare a cursor and ignore the first 54 rows fetched, you could do that, but to what purpose? As rows were added to or deleted from the table, the rows returned would probably change making for some very inconsistent (wrong) results.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Retrieval of particular row in table

Postby ronmathew » Wed Jan 16, 2008 5:33 pm

thanks dick....ya i can skip the first 54 rows fetched using cursors..but what i cant understand is:

There is no 55th row in a table. . . . Tables do not "work that way".
why do u say like that??
ronmathew
 
Posts: 6
Joined: Mon Jan 14, 2008 3:51 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Retrieval of particular row in table

Postby dick scherrer » Wed Jan 16, 2008 11:19 pm

Hello,

I say that because database tables do not have the same attributes as sequential files.

In a PS (qsam) file the records (not rows) are read from "front" to "back". There is no front/back to rows in a database table. A combination of the selection criteria as well as an ordering specification determines what is returned from the table.

Any of the classes or publications that use "the first n " rows of a table is doing the student a disservice.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Retrieval of particular row in table

Postby rawatdewan » Thu Jan 17, 2008 1:26 pm

As per i know u cannot direclty point to a perticular record using cursor so the solution which comes to my mind is that
fetch the records one by one in the cursor and put the fetch statement in a loop which runs exactly 55 times.

eg.
perform para1 55 times
...
para1.
fetch c1 into :ws-var
rawatdewan
 
Posts: 14
Joined: Tue Jan 15, 2008 5:28 pm
Has thanked: 0 time
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post