7.4.10

Oracle pagination

The best way I found, in Oracle 9i/10g RDBMS.

SELECT * FROM (
  SELECT INNER_TABLE.*, ROWNUM PAG_NUM FROM (
    SELECT ...FIELDS..., COUNT(*) OVER() PAG_TOT
    FROM ...
    WHERE ...
    GROUP BY ...
    HAVING ...
    ORDER BY ...
  ) AS INNER_TABLE WHERE ROWNUM < :1
) WHERE PAG_NUM >= :2

As result I have for each row the fields selected and two more fields: PAG_TOT contains the number of rows selected by the inner query, and PAG_NUM that represent the rownum in the inner query.
It resolved a great performance hole, six month ago.

Credits goes to Ask Tom Oracle

Nessun commento:

Posta un commento

Hello, new comment!

Warning

My first language isn't english. Feel free to gently correct my words. :)
Powered By Blogger