Oracle
==============================
PROCEDURE N_PRIMES
( p_num NUMBER)
IS
i INT;
j INT;
nprimes INT;
isprime INT;
BEGIN
i:=2;
nprimes:=0;
<<main_loop>>
WHILE (i<p_num) LOOP
isprime:=1;
j:=2;
<<divisor_loop>>
WHILE (j<i) LOOP
IF (MOD(i,j)=0) THEN
isprime:=0;
EXIT divisor_loop;
END IF;
j:=j+1;
END LOOP ;
IF (isprime=1) THEN
nprimes:=nprimes+1;
END IF;
i:=i+1;
END LOOP;
dbms_output.put_line(nprimes||' prime numbers less than '||p_num);
END;
==================================================================
MySQL
==================================================================
CREATE PROCEDURE sp_nprimes(p_num int)
BEGIN
DECLARE i INT;
DECLARE j INT;
DECLARE nprimes INT;
DECLARE isprime INT;
SET i=2;
SET nprimes=0;
main_loop:
WHILE (i<p_num) do
SET isprime=1;
SET j=2;
divisor_loop:
WHILE (j<i) DO
IF (MOD(i,j)=0) THEN
SET isprime=0;
LEAVE divisor_loop;
END IF;
SET j=j+1;
END WHILE ;
IF (isprime=1) THEN
SET nprimes=nprimes+1;
END IF;
SET i=i+1;
END WHILE;
SELECT CONCAT(nprimes,' prime numbers less than ',p_num);
END;