Page 1 of 1

Retrieval of particular row in table

PostPosted: Mon Jan 14, 2008 4:19 pm
by ronmathew
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...

Re: Retrieval of particular row in table

PostPosted: Wed Jan 16, 2008 1:57 am
by dick scherrer
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.

Re: Retrieval of particular row in table

PostPosted: Wed Jan 16, 2008 5:33 pm
by ronmathew
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??

Re: Retrieval of particular row in table

PostPosted: Wed Jan 16, 2008 11:19 pm
by dick scherrer
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.

Re: Retrieval of particular row in table

PostPosted: Thu Jan 17, 2008 1:26 pm
by rawatdewan
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