0
--Procedures Exercise:
create or replace procedure Display
is
cursor ABC is
select empno, ename, sal
from emp
where deptno=10;
emp_rec ABC%rowtype;
Begin
Open ABC;
Loop
fetch ABC into emp_rec;
exit when ABC%notfound;
end Loop;
dbms_output.put_line(emp_rec.empno||'   '
||emp_rec.ename||'  '||emp_rec.sal);
end;
/

When I execute the following code there is only one output shown for deptno=10, while deptno=10 contains 3 records.

3

You are only printing the last row, not every row:

You need to move the dbms_output inside the loop:

create or replace procedure Display
is
  cursor ABC is
    select empno, ename, sal
    from emp
    where deptno=10;

  emp_rec ABC%rowtype;

Begin
  Open ABC;
  Loop
    fetch ABC into emp_rec;
    exit when ABC%notfound;

    --- the output needs to be here
    dbms_output.put_line(emp_rec.empno||'   '||emp_rec.ename||'  '||emp_rec.sal); 
  end Loop;
end;
/

Not the answer you're looking for? Browse other questions tagged or ask your own question.