0
declare
n number:=3;
begin
while n < 6 loop
n:=&a;
dbms_output.put_line('in loop value less than 6');
end loop;
dbms_output.put_line('value entered is more than 6 thanq');
end; 

my scenario needs to take input from user until he enters some sspecific values in some limit,i tried first this simple code it is not taking value more than one time how can i overcome this

infused
  • 24,000
  • 13
  • 68
  • 78

1 Answers1

0

You need a separate variable to keep track of how many times the loop has run through and what the user input is. The code below will loop properly with i being the amount of loops and &a remaining the user input.

declare
    n number := 3;
    i number := 0;
begin
while i < 6 loop
 i := i + 1;
 n:=&a;
 dbms_output.put_line('in loop value less than 6');
end loop;
 dbms_output.put_line('value entered is more than 6 thanq');
end; 
Major Major
  • 2,697
  • 3
  • 27
  • 35
  • its not working, it is accepting only one value after that it terminates abruptly –  Aug 06 '14 at 08:35
  • If you want to get a new input each time through the loop, you're better served using a different programming language to interact with the user as PL/SQL wasn't meant for that. You can check this answer which may have some workarounds for SQL Plus if you still want to try to continue without using a different language- [http://stackoverflow.com/questions/1870670/how-to-loop-accepting-user-input-with-pl-sql](http://stackoverflow.com/questions/1870670/how-to-loop-accepting-user-input-with-pl-sql) – Major Major Aug 06 '14 at 12:10