Count odd and even digits in a number 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.
Given a number and task is to find the number of odd and even digits present in the number.
Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course by GeeksforGeeks.
Input: 123456 Output: Odd digits = 3 Even digits = 3 Input: 246 Output: Odd digits = 0 Even digits = 3
Approach is to take a number and one by one check its digits, if it is odd or even.
Below is the required implementation:
Odd Digits: 3 Even Digits: 3