Determining the number of fetched rows for a cursor
Determining the number of rows associated with a cursor can be efficiently done by using the cursor_rowCount scalar function which takes a cursor variable as a parameter and returns an integer value as an output corresponding to the number of rows that have been fetched since the cursor was opened.
Before you begin
- A cursor data type must be created.
- A cursor variable of the cursor data type must be declared.
- An OPEN statement referencing the cursor must have been executed.
About this task
Restrictions
The cursor_rowCount function can only be used in SQL PL contexts.
Procedure
Results
Example
connect to sample %
set serveroutput on %
create or replace procedure rowcount_test()
language sql
begin
declare rows_fetched bigint;
declare Designers cursor;
declare first anchor to employee.firstnme;
declare last anchor to employee.lastname;
set Designers = cursor for select firstnme, lastname
from employee where job = 'DESIGNER' order by empno asc;
open Designers;
fetch Designers into first, last;
call dbms_output.put_line(last || ', ' || first);
fetch Designers into first, last;
call dbms_output.put_line(last || ', ' || first);
set rows_fetched = CURSOR_ROWCOUNT(Designers);
call dbms_output.put_line(rows_fetched || ' rows fetched.');
close Designers;
end %
call rowcount_test() %
connect reset %
terminate %