确定游标的已访存行的数目
确定与游标相关联的行数可通过使用 cursor_rowCount 标量函数高效完成,它将游标变量用作参数,并返回对应打开该游标后访存的行数的整数值作为输出。
开始之前
- 必须创建游标数据类型。
- 必须声明游标数据类型的游标变量。
- 必须已执行引用该游标的 OPEN 语句。
关于此任务
限制
cursor_rowCount 函数只能在 SQL PL 上下文中使用。
过程
结果
示例
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 %