SQL pagination support

Db2 12 introduces SQL syntax that enables dividing a query result table into separate pieces, so that, for example, mobile and web applications can present a subset of the rows of the result table at a time.

  • With the growth of web and mobile applications, application developers are looking for more efficient ways to develop good-performing applications. Db2 12 introduces the OFFSET clause to define the number of rows to skip from the beginning of the query result table:

    Begin general-use programming interface information.

    SELECT * FROM TAB OFFSET 10 ROWS FETCH FIRST 10 ROWS ONLY;

    End general-use programming interface information.

  • Also available with Db2 12 is data-dependent pagination, which uses row value expressions in a basic predicate, which enables an application to access part of a Db2 result table based on a logical key value:

    Begin general-use programming interface information.

    WHERE (LASTNAME, FIRSTNAME) > ('SMITH', 'JOHN')

    End general-use programming interface information.

    Prior to Db2 12, such a statement had to be coded as:

    Begin general-use programming interface information.

    WHERE (LASTNAME = 'SMITH' AND FIRSTNAME > 'JOHN') OR (LASTNAME > 'SMITH')

    End general-use programming interface information.