0

Why doesn't the following program prompt user in each iteration of while loop ? It prompt user only once and updates all the records with the same redundant data.

My code:

 Declare 
      counter number(4) := 0 ;
 begin
    counter := &counter ;
    while counter > 0 loop
         insert into test values ( &Id , '&Name' ) ;
         counter := counter - 1 ;
    end loop ;
end ;
Ahtisham
  • 9,170
  • 4
  • 43
  • 57
  • 1
    Did you try running it to see what happens? – Boneist Jan 13 '16 at 15:47
  • Bear in mind that when you use substitution variables, the Oracle client will take the supplied values and replace the parameters with the values before sending the code off to the database to be parsed. – Boneist Jan 13 '16 at 16:19

1 Answers1

2

It will ask you ID and Name only once and insert it into test table as many times as you set the counter.

Dina
  • 48
  • 8
  • how can i ask user again & again for id & name ?? – Ahtisham Jan 13 '16 at 19:31
  • PL/SQL is the wrong language to work with if you're expecting user interaction whilst the code is running. – Boneist Jan 15 '16 at 16:07
  • 1
    PL/SQL alone is not suitable for that, you can [read more about it here](http://stackoverflow.com/questions/1870670/how-to-loop-accepting-user-input-with-pl-sql) – Dina Jan 16 '16 at 17:00