declare
cursor cur_dept is select dname from dept;
v_dname dept.dname%type;
v_cnt integer;
begin
select count(deptno) into v_cnt from dept;
open cur_dept;
loop
fetch cur_dept into v_dname;
exit when cur_dept%notfound;
if cur_dept%rowcount=1 then
dbms_output.put_line(v_dname);
end if;
if cur_dept%rowcount=v_cnt then
dbms_output.put_line(v_dname);
end if;
end loop;
close cur_dept;
end;