Summary
Create a table (PRIME_NUMBERS) where you will store all the prime numbers between (low, high). Create the procedure FIND_PRIME_NUMBERS.
CREATE TABLE PRIME_NUMBERS (num NUMBER(6));
CREATE OR REPLACE PROCEDURE Find_Prime_Numbers(low NUMBER, high NUMBER) IS
tmpVar NUMBER;
non BOOLEAN;
BEGIN
FOR p IN Low .. High LOOP
non := FALSE;
FOR f IN 2..FLOOR(SQRT(p)) LOOP
non := (MOD(p, f) = 0);
EXIT WHEN non;
END LOOP;
IF (NOT non) THEN
INSERT INTO prime_numbers VALUES (p);
sys.DBMS_OUTPUT.PUT_LINE(TO_CHAR(p));
END IF;
END LOOP;
COMMIT;
END Find_Prime_Numbers;
/
Now execute the procedure to find the prime numbers between 0, 10000 and store them to the table.
BEGIN
Find_Prime_Numbers(0, 10000);
END;
/
Query the table prime_numbers to see the results
select * from prime_numbers;