oracle遊標處理多行記錄
declare
cursor cc is select * from emp where sal>(select avg(sal) from emp where deptno=10);
ccrec cc%rowtype;
begin
open cc;
loop
fetch cc into ccrec;
exit when cc%notfound;
dbms_output.put_line(ccrec.empno||'--'||ccrec.ename||'--'||ccrec.job||'--'||ccrec.sal);
end loop;
close cc;
end;
2.查詢各個部門的人數
declare
cursor cc is select b.dname,count(a.empno) as zongshu from emp a,dept b where a.deptno=b.deptno group by b.dname;
ccrec cc%rowtype;
begin
open cc;
loop
fetch cc into ccrec;
exit when cc%notfound;
dbms_output.put_line(ccrec.dname||'----'||ccrec.zongshu);
end loop;
close cc;
end;