oracle没有游标数组的概念。但是你可以定义动态游标,洞首神举个例子:
declare
bm number;
zw varchar2(10);
tt number;
str varchar2(50);
type cur_type is ref cursor; --定义游标类型
cur cur_type; --定义游标变量
begin
str := 'select deptno,sum(sal) from emp group by deptno'; --查询字符串
open cur for str;
dbms_output.put_line('每个部门的工资总和:');
while cur%found loop
dbms_output.put_line(bm||' '||tt);
fetch cur into bm,tt;
end loop;
str:= 'select job,avg(sal) from emp group by job'; --查询字符芹皮串
open cur for str;
dbms_output.put_line('每个职位的工资总和:');
fetch cur into zw,tt;
while cur%found loop
dbms_output.put_line(zw||' '||tt);
fetch cur into zw,tt;
end loop;
end;
每次通过改变str的值,来改变select语句,从而改变游标。
至于循环游标就是这样纳亏:
open cur for str; --打开游标
dbms_output.put_line('每个职位的工资总和:');
fetch cur into zw,tt;
while cur%found loop -- 循环
dbms_output.put_line(zw||' '||tt);
fetch cur into zw,tt;
end loop;--循环结束