オラクルのデモ スキーマスコットを使用して、いくつかの plsql テストを実行します (そのスキーマのデータは決して変更されません)。各部門の従業員番号を取得するために、次のプログラムを作成しました。問題は、部門が 4 つしかないのに、私のプログラムが 5 行を出力したことです。原因がわかりません、どなたか教えていただけないでしょうか?まことにありがとうございます。
declare
cursor employees(department_id number) is
select count(*) howmany
from scott.emp
where deptno=department_id;
employees_per_dept employees%rowtype;
cursor departments is
select *
from scott.dept;
a_department departments%rowtype;
begin
dbms_output.put_line('-----------------------------------');
open departments;
loop
exit when departments%notfound;
fetch departments into a_department;
open employees(a_department.deptno);
fetch employees into employees_per_dept;
dbms_output.put_line(employees_per_dept.howmany);
close employees;
end loop;
close departments;
dbms_output.put_line('-----------------------------------');
end;