Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Prime Number Formula in PL/SQL

Girish SharmaApr 5 2012 — edited Aug 16 2013
Hi Friends,

Oracle 11.2.0.1
Windows XP Prof.

Two questions, but almost same nature :

1.Is there any formula by which we can get the total count of prime numbers for a given number; i mean suppose I says 10, it means it should return 3; i.e. there are total 3 prime number between 1-10.

Here I can use a function which will say me that a given number is prime or not, and i will loop up to that given number. But, this is not actually a Formula, its kind of calculation. I am just looking a fixed matehematical formula for it; if it exists or not. If exists, then how that PL/SQL block will looks like.

2.Suppose I wish to get 50 prime numbers (starting from 1), then what will be the 50th prime number, i mean upto which highest number my calculation will expanded.

If possible, this should also be based upon a fixed formula.

Not actually a business requirement, but my nephew (student of class 9th) asked me these questions. I said him, neither I am student of maths nor that much knowledgeable in PL/SQL.

I asked him, why you are looking these formulas. He said, just these questions raised in my mind and curious to know that is there a fixed formula in maths exists or not. I said him, "Have you asked from your Maths teacher?" He said "Yes, sir told me, that there is no such a fixed mathematical formula, because there is no fixed gap in their ranges, what you says?"

I thought, let me write here.

Regards
Girish Sharma
This post has been answered by Solomon Yakobson on Aug 14 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 13 2013
Added on Apr 5 2012
16 comments
5,061 views