declare
v_counter number := 1000;
begin
for v_counter in 1 .. 10 loop
dbms_output.put_line('In loop v_counter = ' || to_char(v_counter));
end loop;
dbms_output.put_line('After Loop v_counter = ' || to_char(v_counter));
end;
/
What is the value of v_counter after for loop? Let me guess its 10. The strange thing is that within for loop the value of v_counter does change from 1 to 10 but after for loop it reset to 1000. I have found another way of writing this code that works with oracle.
If we use a while loop and increment value of v_counter within loop then it actually preserve the change. look at the following code:
declare
v_counter number := 1000;
begin
v_counter := 0;
while v_counter < 10 loop
dbms_output.put_line('In loop v_counter = ' || to_char(v_counter));
v_counter := v_counter + 1;
end loop;
dbms_output.put_line('After Loop v_counter = ' || to_char(v_counter));
end;
/

New Topic/Question
Reply



MultiQuote






|