# 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.

Examples:

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``    ``-- 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 `

Output:

```Even
```
My Personal Notes arrow_drop_up