This discussion is archived
2 Replies Latest reply: Nov 9, 2011 11:30 AM by Zlatko Sirotic RSS

Control is not getting through the for loop

user2285778 Newbie
Currently Being Moderated
Hi there,

Plz go thru the below proc and help me understand why the control is not entering the for loop. My intention is to populate the table type and finally to display the elements.

--tobj is an object (num, ename, sal);

create or replace procedure obj_Proc as
type objtab is table of tobj;
t objtab:=objtab();
begin
--t:=objtab();
t.extend(5);
t(1):= tobj(1,'Prad',1000);
for i in 1..t.count
loop
dbms_output.put_line('in the loop');
dbms_output.put_line(t(i).num||','||t(i).ename||','||t(i).sal);
end loop;
end;

Thank you
  • 1. Re: Control is not getting through the for loop
    AdamMartin Pro
    Currently Being Moderated
    Your server output is off?

    It works for me.
  • 2. Re: Control is not getting through the for loop
    Zlatko Sirotic Explorer
    Currently Being Moderated
    SQL> create or replace type tobj as object (
      2    num number (2),
      3    ename varchar2 (100),
      4    sal number (10)
      5* )
    
    Type created.
    
    SQL> create or replace procedure obj_Proc as 
      2    type objtab is table of tobj;
      3    t objtab:=objtab(); 
      4  begin
      5    t.extend(5);
      6    t(1):= tobj(1,'Prad',1000);
      7    for i in 1..t.count loop
      8      dbms_output.put_line('in the loop');
      9      dbms_output.put_line(t(i).num||','||t(i).ename||','||t(i).sal);
     10    end loop;
     11  end;
     12  /
    
    Procedure created.
    
    SQL> exec obj_proc;
    
    PL/SQL procedure successfully completed.
    
    
    
    SQL> SET SERVEROUTPUT ON
    
    SQL> exec obj_proc;
    in the loop
    1,Prad,1000
    in the loop
    ,,
    in the loop
    ,,
    in the loop
    ,,
    in the loop
    ,,
    
    PL/SQL procedure successfully completed.
    Regards

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points