GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL
Go To First  |  Previous Question  |  Next Question 
 SQL  |  Question 125 of 171    Print  
how do you generate prime numbers in sql not in plsql

  
Total Answers and Comments: 7 Last Update: March 27, 2008     Asked by: ddkdhar 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
March 17, 2007 15:57:37   #1  
mala        

RE: how do you generate prime numbers in sql not in p...
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

 
Is this answer useful? Yes | No
March 17, 2007 16:05:30   #2  
mala        

RE: how do you generate prime numbers in sql not in p...
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

 
Is this answer useful? Yes | No
March 18, 2007 16:24:40   #3  
ddkdhar Member Since: June 2006   Contribution: 48    

RE: how do you generate prime numbers in sql not in p...
hai mala thanku for answering .
but what is this prime_test table . i want to generate prime numbers in 1 to 100 in sql only .or can u do in plsql
regards

 
Is this answer useful? Yes | No
April 20, 2007 21:42:58   #4  
spoonerboy Member Since: April 2007   Contribution: 1    

RE: how do you generate prime numbers in sql not in p...
The Query doesnt work for the odd numbers which are multiples of 3 and further
Could u please check it out

 
Is this answer useful? Yes | No
February 27, 2008 03:16:04   #5  
Amritendra kumar Member Since: February 2008   Contribution: 16    

RE: how do you generate prime numbers in sql not in plsql
Create sequence Seq
minval 0
maxval 999
startwith 0
incrementby 2
nocache
nocycle;


 
Is this answer useful? Yes | No
March 26, 2008 00:18:45   #6  
saradajasti Member Since: March 2008   Contribution: 6    

RE: how do you generate prime numbers in sql not in plsql
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

 
Is this answer useful? Yes | No
March 27, 2008 03:21:18   #7  
saradajasti Member Since: March 2008   Contribution: 6    

RE: how do you generate prime numbers in sql not in plsql
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

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape