18th Example - Count Area of A Circle on PL/SQL

The circle is of mathematical shape that can be found in the real world such as car wheels, the pipe, cable cross-section. Circle has an area and perimeter that  can be calculated with mathematical formulas. The formula to calculate the area of ​​a circle is pr2, where p is a constant with a value of 3,14 and r is the radius of the circle. The following PL / SQL block to calculate area of ​​a circle:

DECLARE
                phi CONSTANT NUMBER := 3.14;
                r NUMBER;
                hasil NUMBER;
BEGIN
                r := &input_r;
                hasil := phi * r * r;
                DBMS_OUTPUT.PUT_LINE ('Luas Lingkaran = '||hasil);
END;
/


In the declaration of PL/SQL block above there are 3 variables. One variable is the constant phi. Constant is a variable whose value will not change when the program executed. Contents of PL/SQL block that will calculate the area of ​​a circle pr2 value stored in the variable hasil. Suppose we fill the value of the variable r 10, the output shown is "Area of ​​Circle = 314".

No comments

Powered by Blogger.