How do you generate prime numbers in sql not in plsql

Questions by ddkdhar   answers by ddkdhar

Showing Answers 1 - 21 of 21 Answers

mala

  • Mar 17th, 2007
 

hi all,

to generate prime numbers


select decode(n,2,n,
 decode(mod(n,2),1,n,0)) primes from prime_test;


n=== list of numbers in a  coulmn of a table

mala

  Was this answer useful?  Yes

mala

  • Mar 17th, 2007
 

Hi all,

I have just posted the query for prime number generation, that also displays 1 . 1 is not a prime .

This query works well

 select decode(n,1,0,decode(n,2,n,
  decode(mod(n,2),1,n,0))) primes from prime_test;

Regards
Mala

  Was this answer useful?  Yes

saradajasti

  • Mar 26th, 2008
 

SELECT CNT FROM table_name
WHERE MOD(CNT,CNT) = 0
AND MOD(CNT,2) != 0
AND MOD(CNT,3) != 0
AND MOD(CNT,5) != 0
AND MOD(CNT,7) != 0
ORDER BY CNT

  Was this answer useful?  Yes

saradajasti

  • Mar 27th, 2008
 

here CNT is a column name
SELECT CNT FROM table_name
WHERE MOD(CNT,CNT) = 0
AND MOD(CNT,2) != 0
AND MOD(CNT,3) != 0
AND MOD(CNT,5) != 0
AND MOD(CNT,7) != 0
AND MOD(SQRT(CNT),ROUND(SQRT(CNT))) != 0
ORDER BY CNT

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions