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!

SQL Challenge: sequence that produces only primes - most prime numbers win

Sven W.Nov 1 2019 — edited Nov 26 2019

This is a pure fun math challenge.

I got the idea by a recent tweet from M. Rogel.

The task is to create a sequence that produces only prime numbers.

At first you might think this is not possible. But here is a very simple solution:

create sequence mySeq minvalue 2 maxvalue 3 cycle nocache;

Calling mySeq.nextval multiple times will result in: 2,3,2,3,2,3,2,3,...

This command created a sequence that delivered only 2 primes, the highest prime being 3.

The goal is to find a "better" prime generator. the only statement allowed is CREATE SEQUENCE. but you can try any option that it offers.

Better means more different prime numbers. And if the number of different primes is identical, then the sequence with the highest prime wins.
Update: Since the possible number range is very large, I hereby limit the challenge to maxvalue beeing less or equal than 1000000. (Otherwise I will have problems ensuring that all shown numbers are prime).

Post the create statement and the delivered numbers. Every solution that is better then the best previous one will get a helpful.
The best solution will get the "answered" mark.

Btw. I know a solution with 4 primes is theoretically possible. I expect we can find a way with 5 primes.

---

Message was edited by: Sven W.
forgot to add NOCACHE. This is important otherwise we get ORA-04013: number to CACHE must be less than one cycle

This post has been answered by Paulzip on Nov 1 2019
Jump to Answer
Comments
Post Details
Added on Nov 1 2019
16 comments
854 views