PL/SQL Program for Prime Number or Not
Here you will learn pl/sql program for prime number or not using mod function in pl/sql programming.
PL/SQL Program for Prime Number Check
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | DECLARE num NUMBER := &Enter_number; -- Input a number i NUMBER := 2; flag BOOLEAN := TRUE; BEGIN IF num < 2 THEN flag := FALSE; ELSE WHILE i <= SQRT(num) LOOP IF MOD(num, i) = 0 THEN flag := FALSE; EXIT; END IF; i := i + 1; END LOOP; END IF; IF flag THEN DBMS_OUTPUT.PUT_LINE(num || ' is a prime number.'); ELSE DBMS_OUTPUT.PUT_LINE(num || ' is not a prime number.'); END IF; END; / |
Output 1
Enter_number 8
8 is not a prime number.
Output 2
Enter_number 7
7 is a prime number.
Check out our other PL/SQL programs examples