what is the output of the following pl/sql block,
declare
var1 number(2) :=1;
var2 number(2) :=5;
begin
for i in var1..var2 loop
dbms_output.put_line( 'i,var2: ' || i || ','||var2);
if i= 3 then
var2 :=7;
end if;
end loop;
end;
-- James.
what is the output of the following pl/sql block,
declare
var1 number(2) :=1;
var2 number(2) :=5;
begin
for i in var1..var2 loop
dbms_output.put_line( 'i,var2: ' || i || ','||var2);
if i= 3 then
var2 :=7;
end if;
end loop;
end;
-- James.
Just a wild guess!!!!!!!!!!!
Will it give error. Can we change the avue of variable defined in loop namely var2 inside the loop.
No. The pl/sql block works fine
-- James.
Ok.I could not figure the answer and curious to know the same. It a long time that this remains unpublished. James can you kindly post the answer with explanation.
The main doubt in the above PL/SQL block is whether the variable used in the loop can be modified.
Actually, it can be modified, so that after the modification the variable takes up the new value & proceeds with the loop processing.
So the output of the above block is,
i,var2: 1,5
i,var2: 2,5
i,var2: 3,5
i,var2: 4,7
i,var2: 5,7
*** Innila ***
You are right...but though the value of var2 is modified as 7 the loop is getting processed up to 5 only which means new value of Var2 does not afect the the loop.