title: oracle sql pagination with total pages or total entries
body: <p>I'm trying to access paginated results from a DB. Following the below query:</p>
  
  <pre><code>SELECT * FROM
  (
      SELECT a.*, rownum r__
      FROM
      (
          SELECT * FROM ORDERS WHERE CustomerID LIKE 'A%'
          ORDER BY OrderDate DESC, ShippingDate DESC
      ) a
      WHERE rownum &lt; ((pageNumber * pageSize) + 1 )
  )
  WHERE r__ &gt;= (((pageNumber-1) * pageSize) + 1)
  </code></pre>
  
  <p>from <a href="https://stackoverflow.com/a/241643/4242499">here</a> , I am able to achieve pagination.</p>
  
  <p>I modified the query like below inorder to get total counts as well :</p>
  
  <pre><code>SELECT * FROM
  (
      SELECT a.*, rownum r__ , count(OrderDate)
      FROM
      (
          SELECT * FROM ORDERS WHERE CustomerID LIKE 'A%'
          ORDER BY OrderDate DESC, ShippingDate DESC
      ) a    group by OrderDate
  ) 
  WHERE r__ between (pageNumber * pageSize )+ 1 and (pageNumber *pageSize) + pageSize;
  </code></pre>
  
  <p>But I also want to calculate the total number of pages and if the requested page is the last page as well. I tried to get the <code>COUNT</code> of the inner query so that I can calculate the total pages inside my code, but I could not get it. I've tried by <code>COUNT(ORDERDATE)</code> and grouping but it does not work.</p>
  
  <p>Please tell me how I can achieve this.</p>