September 3, 2012 in Database
A very common requirement is to have pagination on the level of the database especially if your query result returns thousands of database records. This post shows you how to make database pagination in DB2.
In order to make a database pagination in DB2, you need to use the ROW_NUMBER() function as follows.
WITH CVIEW (SELECT column1, column2, column3, ROW_NUMBER() OVER (ORDER BY column1) AS RN FROM TABLE(OR VIEW) WHERE column1=xyz1 and column2=xyz2) SELECT column1, column2, column3 FROM CVIEW WHERE RN BETWEEN X AND Y ORDER BY RN
You can use this template query if you want to retrieve records from
Y from the
TABLE(OR VIEW). The template query shows you how to retrieve
column3 from the
TABLE(OR VIEW) with the specified condition
column1=xyz1 and column2=xyz2 ordered by
This is all about.