Sum of the first and last digit of 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 n, the task is to find the sum of its first and last digit.
Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course by GeeksforGeeks.
Input: 14598. Output: Sum of the first and last digit is 9. Input: 987456. Output: Sum of the first and last digit is 15.
Approach is to use the substr() function and store the first and last digit and then print their sum.
Below is the required implementation:
Sum of the first and last digit is 9