Skip to main content

Pl/SQL Program to make calculator using StandAlone Function

create or replace function addmy_num(x in number, y in number) return number is
  z number;
begin
  z := x + y;
  return z;
end;

create or replace function subtractmy_num(x in number, y in number) return number is
  z number;
begin
  z := x - y;
  return z;
end;
   
create or replace function multiplymy_num(x in number, y in number) return number is
  z number;
begin
  z := x * y;
  return z;
end;

create or replace function dividemy_num(x in number, y in number) return number is
  z number;
begin
  z := x / y;
  return z;
end;

declare
  a number;
  b number;
  c number;
  choice varchar2(10);
  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_num(a,b);
          dbms_output.put_line('the addition of two  number '|| c);
          when '-' then
             c:=subtractmy_num(a,b);
                 dbms_output.put_line('the subtraction of two  number '|| c);
            when '*' then
                c:=multiplymy_num(a,b);
                    dbms_output.put_line('the multiply of two  number '|| c);
                when '/' then
                   c:=dividemy_num(a,b);
                       dbms_output.put_line('the divide of two  number '|| 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;