If you are using Oracle8i or higher, you may think of using
some analytical function for counts, row numbers, a.s.o.
For example, for SCOTT.EMP table, you may have
/* this is the total rows count */,
COUNT(EMPNO) OVER (),
/* this is the row number of each row in the indicated ordering */
ROW_NUMBER OVER(ORDER BY ENAME)
ORDER BY ENAME
These functions are very powerful and versatile, having lots of possibilities, maybe they could help you to solve the problem.