PL/SQL Script to create a procedure to calculate and return the area of a triangle

Hello guys i really need some help with oracle procedures and functions, I am a newbie in Oracle RDBMS and I can't seem to get the hang of it. Here is the question: Define the Oracle PL/SQL script to create a procedure to calculate the area of a triangle: 1. Assuming it's a right angled triangle. 2. Assuming you have only been given the lengths of each if the 3 sides.

2 answers

  • answered 2019-07-18 16:54 APC

    Here's a function which uses Heron's formula:

    create or replace function area_of_triangle 
       ( a in number, b in number, c in number)
       return number 
    is
        s number;
        t_area number;
    begin
        -- calculate semiperimeter
        s := (a + b + c) / 2;
    
        -- calculate area
        t_area := sqrt(s * (s - a) * (s - b) * (s - c) );
    
        return t_area;
    end;
    /
    

  • answered 2019-07-19 05:40 Chalo

    declare
    base integer;
    height integer;
    area integer;
    BEGIN
    height:= 12;
    base := 10;
    dbms_output.put_line('Height = '||height);
    dbms_output.put_line('Base = '||base);
    area := 0.5 * base * height;
    
    dbms_output.put_line('The area of the triangle is ' ||area);
    end;