Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Check whether a given number is even or odd in PL/SQL

  • Difficulty Level : Basic
  • Last Updated : 02 Jul, 2018

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.


Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

Input: 2 
Output: even

Input: 5
Output: odd

The approach is to divide the given number by 2 and if the remainder is 0 then the given number is even else odd.

Below is the required implementation:

    -- Declare variable n, s, r, len
    -- and m of datatype number
    n NUMBER := 1634;
    r NUMBER;
    -- Calculating modulo
    r := MOD(n, 2);
    IF r = 0 THEN
    END IF;
--End program 


My Personal Notes arrow_drop_up
Recommended Articles
Page :