Skip to main content

PL/SQL Program of making calculator using functions

declare
  a number;
  b number;
  c number;
  choice varchar2(10);
  function dividemy(x in number, y in number) return number is
  z number;
begin
  z := x / y;
  return z;
end;
 function multiplymy(x in number, y in number) return number is
  z number;
begin
  z := x * y;
  return z;
end;

 function subtractmy(x in number, y in number) return number is
  z number;
begin
  z := x - y;
  return z;
end;

 function addmy(x in number, y in number) return number is
  z number;
begin
  z := x + y;
  return z;
end;

  begin
    dbms_output.put_line('Enter the first number');
    a:=&enternum1;
    dbms_output.put_line('Enter the second number');
    b:=&enternum2;
    dbms_output.put_line('Enter your operation choice');
    choice:='&symbol';
   /* if choice='+' then
      c:=addmy_num(a,b);
    else if choice='-' then
      c:=subtract(a,b);
    else if choice='*' then
      c:=multiply(a,b);
    else if choice='/' then
      c:=divide(a,b); */
     
      case choice
        when '+' then
          c:=addmy(a,b);
          dbms_output.put_line('The addition of two number is : '||c);
          when '-' then
             c:=subtractmy(a,b);
          dbms_output.put_line('The subtraction of two number is : '||c);
             when '*' then
                c:=multiplymy(a,b);
                dbms_output.put_line('The multiplication of two number is : '||c);
                when '/' then
                   c:=dividemy(a,b);
                   dbms_output.put_line('The Divide of two number is : ' ||c);
           
    else
      dbms_output.put_line('No option selected');
    end case;
  end;


Comments

Popular posts from this blog

Pl/SQL program to find square of a user input number Using Function

declare   value1 number;   value2 number;   mytotal number;   function myfun(myval1 in number, myval2 in number) return number is     total number;   begin     total := myval1 ** myval2;     dbms_output.put_line(total);     return total;   end; begin   value1 :=&val1;   value2 := &val2;  mytotal:= myfun(value1, value2); end;