Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: PL/SQL question regarding nested loops

Re: PL/SQL question regarding nested loops

From: B. Williams <willdrama_at_hotmail.com>
Date: Fri, 4 Aug 2006 09:16:35 -0400
Message-ID: <WMHAg.67433$9c6.46631@dukeread11>

<eugenio.spadafora_at_gmail.com> wrote in message news:1154689104.667374.56730_at_b28g2000cwb.googlegroups.com...
> You forgot to reset J to 1 before
>> while j <= 2 loop
> and you should put
>> exit when i = 3;
> after the first
>> end loop;
>
> Ciao
> Eugenio
>
> B. Williams wrote:
>> I have some code that uses for loops and I chaged the outer loop into a
>> simple loop and inner loop into a while loop, but the out put is coming
>> out
>> different. The outer loop is supposed to run 3 times while the inner
>> loops
>> is supposed to run 6 times. Wouls someone look at my code and tell me
>> what I
>> have done wrong. Thanks in advance.
>>
>> Original code
>> set serveroutput on
>> declare
>> v_test NUMBER := 0;
>> begin
>> <<outer_loop>>
>> for i IN 1..3 loop
>> dbms_output.put_line('Outer Loop');
>> dbms_output.put_line('i = ' || i);
>> dbms_output.put_line('v_test = ' || v_test);
>> v_test := v_test + 1;
>> <<inner_loop>>
>> for j IN 1..2 loop
>> dbms_output.put_line('Inner Loop');
>> dbms_output.put_line('j = ' || j);
>> dbms_output.put_line('i = ' || i);
>> dbms_output.put_line('v_test = ' || v_test);
>> end loop Inner_Loop;
>> end loop outer_loop;
>> end;
>> /
>>
>> Modified code
>>
>> set serveroutput on
>> declare
>> i PLS_INTEGER := 0;
>> j PLS_INTEGER := 1;
>> v_test NUMBER := 0;
>> begin
>> loop
>> i := i + 1;
>> dbms_output.put_line('Outer Loop');
>> dbms_output.put_line('i = ' || i);
>> dbms_output.put_line('v_test = ' || v_test);
>> v_test := v_test + 1;
>> exit when i = 3;
>> while j <= 2 loop
>> dbms_output.put_line('Inner Loop');
>> dbms_output.put_line('j = ' || j);
>> dbms_output.put_line('i = ' || i);
>> dbms_output.put_line('v_test = ' || v_test);
>> j := j + 1;
>> end loop;
>> end loop;
>> end;
>> /
>

Thanks, I knew it was something simple I was missing. Received on Fri Aug 04 2006 - 08:16:35 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US