Prerequisite – PL/SQL introduction
A prime number is a whole number greater than 1, which is only divisible by 1 and itself. First few prime numbers are : 2 3 5 7 11 13 17 19 23 …..
In PL/SQL code groups of commands are arranged within a block. A block group-related declarations or statements.
In declare part, we declare variables and between begin and end part, we perform the operations.
Examples:
Input : 5
Output : true
Input : 10
Output : false
Below is the required implementation:
SQL
declare
n number;
i number;
temp number;
begin
n := 13;
i := 2;
temp := 1;
for i in 2..n/2
loop
if mod(n, i) = 0
then
temp := 0;
exit;
end if;
end loop;
if temp = 1
then
dbms_output.put_line( 'true' );
else
dbms_output.put_line( 'false' );
end if;
end ;
|
Output:
true
Last Updated :
13 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...