[Dica] Select dos NÚMEROS PRIMOS
Enviado: Seg, 31 Out 2005 12:32 pm
Olá pessoal... Pra quem não sabe, eu estudo Matemática aplicada a Informática na ULBRA. (ou seja, adoro cálculos!). Já fazia um tempo que eu queria montar um select que gera os números primos. Finalmente, hoje eu consegui!!!
SQL DOS NÚMEROS PRIMOS
Aí vai ele:
SQL DOS NÚMEROS PRIMOS
select z.zz PRIMOS
from
(select rownum+1 zz
from user_tables
where rownum < 100
) z
where zz not in (
select y.bb
from (select rownum+1 aa from user_tables a where rownum < 100) x
, (select rownum+1 bb from user_tables b where rownum < 100) y
where bb<>aa
and mod(bb, aa)=0
and aa<=bb
)
/
SQL> select z.zz PRIMOS
2 from
3 (select rownum+1 zz
4 from user_tables
5 where rownum < 100
6 ) z
7 where zz not in (
8 select y.bb
9 from (select rownum+1 aa from user_tables a where rownum < 100) x
10 , (select rownum+1 bb from user_tables b where rownum < 100) y
11 where bb<>aa
12 and mod(bb, aa)=0
13 and aa<=bb
14 )
15 /
PRIMOS
---------
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
25 rows selected.
SQL>