Home » SQL & PL/SQL » SQL & PL/SQL » loops
loops [message #39314] Fri, 05 July 2002 20:13 Go to next message
christy
Messages: 6
Registered: May 2002
Junior Member
I trying to do a procedure that has a loop that when you input an number such as 2,8 you get a loop that gets that loops the values between 2-5 but I want to also print that out as

2
3
4
5

how is this done....I'm kinda new at this and cant figure it out
this is my code so far....I would appreciate any help
Thank you :)

PROCEDURE test (v_number_begin number, v_number_end number)
IS

BEGIN
For loop in v_number_begin..v_number_end
Loop
text_io.put_line(v_number_begin);

End loop;


END;
Re: loops [message #39315 is a reply to message #39314] Fri, 05 July 2002 21:38 Go to previous messageGo to next message
Balaji
Messages: 102
Registered: October 2000
Senior Member
hi
try this, pretty simple

1 create or replace procedure tryloop(beginnum in number,endnum in number) is
2 begin
3 for i in beginnum..endnum loop
4 dbms_output.put_line(i);
5 exit when i>=endnum;
6 end loop;
7* end;
SQL> /

Procedure created.

SQL> set serveroutput on
SQL> exec tryloop(1,10);
1
2
3
4
5
6
7
8
9
10

PL/SQL procedure successfully completed.

SQL> exec tryloop(2,8);
2
3
4
5
6
7
8

PL/SQL procedure successfully completed.

rgds
Balaji.K.L
Re: loops [message #39317 is a reply to message #39314] Sat, 06 July 2002 00:57 Go to previous messageGo to next message
Balaji
Messages: 102
Registered: October 2000
Senior Member
yes ! i know that
but i feel using exit in a loop is good practise. there might be some cases where we have to come out, when a certain criteria is matched before the loop
ends.

rgds
Balaji
Re: loops [message #39319 is a reply to message #39314] Sat, 06 July 2002 09:16 Go to previous messageGo to next message
christy
Messages: 6
Registered: May 2002
Junior Member
Thanks so much...got it :) I'm going to try that...
Re: loops [message #39324 is a reply to message #39314] Sun, 07 July 2002 22:27 Go to previous message
Dipika
Messages: 1
Registered: July 2002
Junior Member
create or replace procedure tot(a in number,b in number)is
begin

for i in a..b loop
dbms_output.put_line(i);
end loop;
end;
Previous Topic: Help
Next Topic: ORA-01552 non-system tablespace
Goto Forum:
  


Current Time: Mon Jun 03 00:56:16 CDT 2024