ROWNUM pseudocolumn
Any unresolved and unqualified column reference to the ROWNUM pseudocolumn is converted to the OLAP specification ROW_NUMBER() OVER().
Enablement
You enable ROWNUM pseudocolumn support by setting the DB2_COMPATIBILITY_VECTOR registry variable to hexadecimal value 0x01 (bit position 1), and then stop and restart the instance to have the new setting take effect.db2set DB2_COMPATIBILITY_VECTOR=01
db2stop
db2startTo take full advantage of the Db2® compatibility features for Oracle applications, the recommended setting for the DB2_COMPATIBILITY_VECTOR is ORA, which sets all of the compatibility bits.
ROWNUM numbers the records in a result set. The first record that meets the WHERE clause criteria in a SELECT statement is given a row number of 1, and every subsequent record meeting that same criteria increases the row number.
Both ROWNUM and ROW_NUMBER() OVER() are allowed in the WHERE clause of a subselect and are useful for restricting the size of a result set. If you use ROWNUM in the WHERE clause and there is an ORDER BY clause in the same subselect, the ordering is applied before the ROWNUM predicate is evaluated. Similarly, if you use the ROW_NUMBER() OVER() function in the WHERE clause and there is an ORDER BY clause in the same subselect, the ordering is applied before the ROW_NUMBER() OVER() function is evaluated. If you use the ROW_NUMBER() OVER() function in the WHERE clause, you cannot specify a window-order-clause or a window-partition-clause.
- A column within the current SQL query
- A local variable
- A routine parameter
- A global variable
Avoid using 'ROWNUM' as a column name or a variable name while ROWNUM pseudocolumn support is enabled.
Example
SELECT TEXT FROM SESSION.SEARCHRESULTS
WHERE ROWNUM BETWEEN 20 AND 40
ORDER BY IDNote that ROWNUM is affected by
the ORDER BY clause.