Get total count of rows in pagination query

后端 未结 1 982
礼貌的吻别
礼貌的吻别 2021-02-09 08:31

I have the following query for record pagination

SELECT *
  FROM (SELECT e.*, 
               ROWNUM row_num
          FROM (SELECT emp_no,
                              


        
相关标签:
1条回答
  • 2021-02-09 08:39

    A typical pagination query with the total number of rows would be:

    SELECT *
      FROM (SELECT outr.*,
                   ROWNUM row_num
              FROM (SELECT emp_no,
                           emp_name,
                           dob,
                           count(*) over () total_nb
                      FROM emp
                     ORDER BY ...) outr
             WHERE ROWNUM < ((pagenum * row_size) + 1))
     WHERE row_num >= (((pagenum - 1) * row_size) + 1)
    

    Don't forget the ORDER BY.

    0 讨论(0)
提交回复
热议问题