Prerequisite – PL/SQL Introduction
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.
Write a script in PL/SQL to display all the prime numbers between any two positive whole numbers.
Here, all the prime numbers between any two numbers taken as input as the upper limit and the lower limit are returned.A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers.
In this implementation, the number of divisors of a number that occurs between the two limits is counted which should be 2 (1 and the number itself). If the number of divisors is 2, then that number is returned.
For example, consider the number 5. It has only two divisors: 1 and the number 5 itself.
Hence, it is a prime number.
Input: 10 20 Output: 11 13 17 19 Input: 20 30 Output: 23 29
Below is the implementation :
Input: Enter the lower and higher limit:1 10 Output: 2 3 5 7
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.