Results 1 to 6 of 6

Thread: try this...

  1. #1
    Expert Member
    Join Date
    Jun 2006
    Answers
    410

    try this...

    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.


  2. #2
    Expert Member
    Join Date
    May 2006
    Answers
    114

    Re: try this...

    Just a wild guess!!!!!!!!!!!
    Will it give error. Can we change the avue of variable defined in loop namely var2 inside the loop.


  3. #3
    Expert Member
    Join Date
    Jun 2006
    Answers
    410

    Re: try this...

    No. The pl/sql block works fine

    -- James.


  4. #4
    Expert Member
    Join Date
    May 2006
    Answers
    114

    Re: try this...

    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.


  5. #5
    Expert Member
    Join Date
    Sep 2006
    Answers
    130

    Re: try this...

    Quote Originally Posted by RyanJames View Post
    Just a wild guess!!!!!!!!!!!
    Will it give error. Can we change the avue of variable defined in loop namely var2 inside the loop.
    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 ***

  6. #6
    Expert Member
    Join Date
    Jun 2006
    Answers
    410

    Re: try this...

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact