Yes, it is inefficient. I was trying to give a "pure SQL" solution as this is a "pure SQL" forum. If you want to display a total number of selected records at the end, then probably your DBMS already has a built-in way to do this. For example, in Oracle SQL Plus:
Code:
SQL> select * from dept;
DEPTNO DNAME LOC MGR
---------- -------------- ------------- ----------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS 7782
30 SALES CHICAGO
40 OPERATIONS BOSTON
4 rows selected.
And in Oracle PL/SQL:
Code:
SQL> declare
2 cursor c is select * from dept;
3 r c%ROWTYPE;
4 begin
5 open c;
6 loop
7 fetch c into r;
8 exit when c%notfound;
9 end loop;
10 dbms_output.put_line('Number of rows='||c%rowcount);
11 close c;
12 end;
13 /
Number of rows=4
PL/SQL procedure successfully completed.