Function To Find A Number Is Prime In Sql

We will write  a funciton that finds given number is Prime. The function gets a number parameter and return bit value (1 or 0). If returns 1 that means the number is prime else returns 0 then the number is non-prime

After running the code above we will get succesfull message. Then we can use the function like below.

Example 1:

Result:0

Example 2:

Result:1

Not: We can use the function in a query

Example 3 

List all books and whether pageCount is Prime Or not

Example 4 

List the books which pageCount is prime

CLICK HERE TO SEE MORE EXAMPLE ABOUT SCALAR VALUED FUNCTIONS

YOU MAY WANT TO SEE OUR ALL EXAMPLES PAGE, THEN CLICK HERE

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: