Using ROWNUM and DUAL in DB2 9.7

The ROWNUM and DUAL supports are enabled by setting the DB2_COMPATIBILITY_VECTOR registry variable to ORA.

Oracle programmers use ROWNUM quite often to retrieve a controlled number of rows from a SQL statement. The same can be applied in DB2 9.7.

Getting ready

Enable the compatibility feature by setting the DB2_COMPATIBILITY_VECTOR registry to ORA.

How to do it...

In earlier versions of DB2, when we wanted to return only a specific number of rows of an SQL statement, we used the FETCH FIRST clause. Now that we have the Oracle compatibility feature enabled in DB2 9.7, we can use ROWNUM as in Oracle. In DB2, ROWNUM supports<, >, >=, <=, =, and BETWEEN operators.

We can combine ROWID and ROWNUM together to display the ...

Get IBM DB2 9.7 Advanced Application Developer Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.