Home
> IT Answers
> AS/400
> i want to read first 5 records and want to skip the next 5 records and want to read another 5 records in a db2 table using cursor.? how do i do that
When I come across someone specifying "first" or "next" or "last" in a discussion of RDBMS rows, I must remind you that there is no logical sequence to any data stored in an RDBMS (DB2 or other).
So, with that knowledge, you must have an ORDER BY in your CURSOR. Only an ORDER BY (or something else to force a sort) will put rows into some guaranteed sequence.
And since an ORDER BY happens just before the data is returned to your application the only way to "skip" rows returned by the cursor is to FETCH 5 times without processing them.
This raises a question in my mind... why would you want to do this?
I have to believe that if you define your selection criteria better, you could develop a query that would return ONLY the rows you want. That is the proper method.
Steve
Last Wiki Answer Submitted: July 27, 2009 8:23 pm by Meandyou5,205 pts.
If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.