21st Example - Count the Average and Categorizes on PL/SQL
On an assessment will be obtained
many different values. Those values can be calculated mean values. The average value can be grouped into
certain groups. Suppose
there are found 5 values 60,70,80,90,50.
The summarized values can be calculated the average score is 70. Defined 3
categories, LOW if the average value of <60, MID if the average
value of 60-85 and HIGH if the average
value of> 85. The following
PL/SQL block to perform the calculation:
DECLARE
n1 NUMBER;
n2 NUMBER;
n3 NUMBER;
n4 NUMBER;
n5 NUMBER;
rata NUMBER;
kat VARCHAR2(8);--LOW/MID/HIGH
BEGIN
n1 := 60;
n2 := 70;
n3 := 80;
n4 := 90;
n5 := 50;
rata := (n1+n2+n3+n4+n5)/5;
IF rata > 85 THEN
kat := 'HIGH';
ELSIF rata BETWEEN 60 AND 85 THEN
kat := 'MID';
ELSE
kat := 'LOW';
END IF;
DBMS_OUTPUT.PUT_LINE (The category is '||kat);
END;
/
There
are 5 variables
n1, n2, n3,
n4, n5. Average variable will summarized values and then divided by five to
obtain the average value. Checking category performed
using conditional statements IF
.. END IF.
For the case above, the output shown is "The
category is MID".
Leave a Comment