ROWCOUNT returns the number of affected rows not only for DML, but also for SELECT statements.
--- code starts here ---
set serverotuput on;
declare
i number;
j number;
cursor c1 is select col1 from tab1;
begin
-- count the rows
select count(col1) into i from tab1;
-- loop over table with cursor
open c1;
loop
fetch c1 into j;
exit when c1%notfound;
end loop;
j := c1%ROWCOUNT;
close c1;
dbms_output.put_line('COUNT(*): ' || i);
dbms_output.put_line('ROWCOUNT: ' || j);
end;
/
--- code ends here ---
output:
COUNT(*): 4
ROWCOUNT: 4
It is better to ask and appear ignorant, than to remain silent and remain ignorant.
Oracle OCP DBA 9i,
C++, Java developer