Home » SQL & PL/SQL » SQL & PL/SQL » loops&cursors
loops&cursors [message #437] Tue, 12 February 2002 02:02 Go to next message
ratna
Messages: 7
Registered: October 2001
Junior Member
hi!,I am new to ORACLE.I was trying with loop to get all prime numbers,but could not do.
How can I do it with loop.
I created a Table messages with one field(results) and then tried to view the result.
I am also not getting clear with loops,cursors.
where can i view examples to get myself clear.
Thanks in advance.
Re: loops&cursors [message #438 is a reply to message #437] Tue, 12 February 2002 02:35 Go to previous messageGo to next message
pratap kumar tripathy
Messages: 660
Registered: January 2002
Senior Member
here is an example ..try and see(it display all prime numbers between 2 and 100

set serveroutput on

declare
begin
for i in 2..100
loop
for j in 2..trunc(sqrt(i))
loop
if mod(i,j)=0 then goto c; end if;
end loop;
dbms_output.put_line(to_char(i));
<<c>> null;
end loop;
end;
Re: loops&cursors [message #462 is a reply to message #437] Thu, 14 February 2002 00:27 Go to previous messageGo to next message
ratna
Messages: 7
Registered: October 2001
Junior Member
Thanks this works but 2ND option didnot work and gave error.
Re: loops&cursors [message #1751 is a reply to message #437] Sun, 26 May 2002 17:26 Go to previous message
Stephanie
Messages: 5
Registered: March 2002
Junior Member
is there another way of doing a loop for prime numbers besides taking the square root? No other easier way. Because I have to do prime numbers form 10000 to 10100
Previous Topic: parameterized view
Next Topic: Cursors in Oracle 8i
Goto Forum:
  


Current Time: Thu Apr 25 18:55:10 CDT 2024