Here you will get a pl/sql program for prime number.

A number is a prime number if it is divisible by 1 or itself. For example 2, 3, 5, 7, etc are prime numbers.

While numbers like 4, 6, 8, etc are not prime.

## PL/SQL Program for Prime Number

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
declare n number; i number; flag number; begin i:=2; flag:=1; n:=&n; for i in 2..n/2 loop if mod(n,i)=0 then flag:=0; exit; end if; end loop; if flag=1 then dbms_output.put_line('prime'); else dbms_output.put_line('not prime'); end if; end; / |

**Output**

*Enter value for n: 12*

*old 9: n:=&n;*

*new 9: n:=12;*

*not prime*

Very Helpful

Thank you!!!

Hii …we want full pl/SQL programme’s if don’t mine it will we send to my site.

Very Helpfull

Thanks You

sir, why are we using n/2 in for loop. Please explain

if half of the values of n does not give remainder 0 then the higher values preceding n/2 will also not give reminder zero and it also improves performance of the code as you are executing the condition for half of the length.

hope u got it.

Wont work if input is 2 . For input 2 it will show not a prime.

it worked bro

thanks

PL SQL Program to print sum of first 10 Prime numbers

very nice

i need a program to print sum of first 10 prime numbers in pl/sql.

hai Neeraj Mishra you are doing a grate job i like your programming .but i have one doubt in prime number program by plsql .why we take n/2 to in mod function could you please explain this.except this i have understood all you programs. please reply to me .