# Prime number in PL/SQL

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:

`declare` ` ` `-- declare variable n, i ` `-- and temp of datatype number ` `n number; ` `i number; ` `temp` `number; ` ` ` `begin` ` ` `-- Here we Assigning 10 into n ` `n := 13; ` ` ` `-- Assigning 2 to i ` `i := 2; ` ` ` `-- Assigning 1 to temp ` `temp` `:= 1; ` ` ` `-- loop from i = 2 to n/2 ` ` ` `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` `; ` ` ` `-- Program End ` |

*chevron_right*

*filter_none*

Output:

true

## Recommended Posts:

- Count occurrences of a prime number in the prime factorization of every element from the given range
- Print the nearest prime number formed by adding prime numbers to N
- Check if a prime number can be expressed as sum of two Prime Numbers
- Find coordinates of a prime number in a Prime Spiral
- Number which has the maximum number of distinct prime factors in the range M to N
- Represent a number as a sum of maximum possible number of Prime Numbers
- Largest number less than N whose each digit is prime number
- Find third number such that sum of all three number becomes prime
- Kth prime number greater than N
- Nearest prime less than given number n
- Given a number x , find y such that x*y + 1 is not a prime
- Sum of all the prime divisors of a number
- Twisted Prime Number
- k-th prime factor of a given number
- N-th prime factor of a given number

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.