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 three numbers and the task is to find out the sum and average of three numbers.
Examples:
Input: a = 12, b = 15, c = 32
Output: sum = 59 avg = 19.66
Input: a = 34, b = 45, c = 11
Output: sum = 90 avg = 30
Approach is to take three numbers and find their sum and average using the formula given below-
Sum: 
Average: 
Where a,b,c are the three numbers.
Below is the required implementation:
DECLARE
a NUMBER := 12;
b NUMBER := 14;
c NUMBER := 20;
sumOf3 NUMBER;
avgOf3 NUMBER;
BEGIN
sumOf3 := a + b + c;
avgOf3 := sumOf3 / 3;
dbms_output.Put_line( 'Sum = '
||sumOf3);
dbms_output.Put_line( 'Average = '
||avgOf3);
END ;
|
Output:
Sum = 46
Average = 15.33