I have created a simple calculator using concept of packages and functions in plsql
if there is any query you can comment below
create or replace package my_calci as
function addition(a in number,b in number) return number;
function subtraction(a in number,b in number) return number;
function multiplication(a in number,b in number) return number;
function division(a in number,b in number) return number;
end my_calci;
create or replace package body my_calci as
function addition(a in number,b in number) return number is
z number;
begin
z := a + b;
return z;
end addition;
function subtraction(a in number,b in number)
return number
as
z number;
begin
z := a - b;
return z;
end subtraction;
function multiplication(a in number,b in number) return number as
z number;
begin
z := a * b;
return z;
end multiplication;
function division(a in number,b in number) return number as
z number;
begin
z := a / b;
return z;
end division;
end my_calci;
declare
ch varchar2(5);
input1 number;
input2 number;
output number;
begin
input1 :=&Enter_no_1;
input2 :=&Enter_no_2;
ch :='&Enter_choice';
case ch
when '+' then
output := my_calci.addition(input1,input2);
dbms_output.put_line(output);
when '-' then
output := my_calci.subtraction(input1,input2);
dbms_output.put_line(output);
when '*' then
output := my_calci.multiplication(input1,input2);
dbms_output.put_line(output);
when '/' then
output := my_calci.division(input1,input2);
dbms_output.put_line(output);
else dbms_output.put_line('Wrong_input');
end case;
end;
No comments:
Post a Comment