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.

closed as off-topic by Michael Green, Shanky, ypercubeᵀᴹ, Marian, Paul White May 9 '16 at 11:18

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – Michael Green, Shanky, ypercubeᵀᴹ, Marian, Paul White
If this question can be reworded to fit the rules in the help center, please edit the question.

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.