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

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.

Examples:

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

DECLARE
    -- Declare variable n, s, r, len
    -- and m of datatype number
    n NUMBER := 1634;
    r NUMBER;
BEGIN
    -- Calculating modulo
    r := MOD(n, 2);
  
    IF r = 0 THEN
      dbms_output.Put_line('Even');
    ELSE
      dbms_output.Put_line('Odd');
    END IF;
END;
--End program 

chevron_right


Output:

Even
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.