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...
Retrieval of particular row in table
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: Retrieval of particular row in table
Hello,
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.
There is no 55th row in a table. . . . Tables do not "work that way".for example the 55 th row from 100 rows
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.
d.sch.
-
- Posts: 6
- Joined: Mon Jan 14, 2008 3:51 pm
- Skillset: COBOL,DB2,CICS,VSAM,JCL
- Referer: Through net
Re: Retrieval of particular row in table
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??
There is no 55th row in a table. . . . Tables do not "work that way".
why do u say like that??
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: Retrieval of particular row in table
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.
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.
d.sch.
-
- Posts: 14
- Joined: Tue Jan 15, 2008 5:28 pm
- Skillset: cobol,jcl,db2
- Referer: internet
Re: Retrieval of particular row in table
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
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