For starters, let us look at a PL/SQL program to add two numbers or integers and fetching the result into a third variable.
This program takes two inputs one for each variable and adds the result to a third variable and prints it.
PL/SQL Program To Add Two Numbers
Declare Var1 integer; Var2 integer; Var3 integer; Begin Var1:=&var1; Var2:=&var2; Var3:=var1+var2; Dbms_output.put_line(var3); End; /
Output
Since, we need variables in this program code so we need to declare them in the declaration section. In the begin section, we need to initialize and take input from the user. All the logical and mathematical calculations for this program logic need to be established here.
Var1:=&var1;
This statement assigns the value that the user enters for the variable. Similarly, we have taken input for next variable.
Var3:=var1+var2
This statement is used to assign the calculated values of Var1 and Var2 into the third variable.
Dbms_output.put_line()
The statement takes a parameter which can be printed onto the console screen.
Note: For this statement to work properly, it is sometimes necessary to use a particular statement as mentioned below:
When you start the SQL Command Prompt/Terminal, just type:
Set serveroutput on;
This statement is used to activate the working of print statement on the console screen. This will help to get the proper output onto the screen/terminal as expected.
Finally, the End statement is used to terminate the code.
thanks!!!!!!!!
hii…thank you it was very helpful
can you explain how to find largest of 2/3 numbers?
declare
var1 number;
var2 number;
begin
var1:=&var1;
var2:=&var2;
if var1<var2 then
dbms_output.put_line('var2 is greater');
else
dbms_output.put_line('var1 is greater');
end if;
end;
/
Thank u sir for sharing this program
thank you sir for sharing this program……
not working in oracle12g
hello, please put on algorithm steps from program codings in pL/SQL
hello!!! pls update some crucial informations and some programs in below email.
why are you using ( := ) this operator ?
please explain now my comment …
bcoz its the way we assign value to variable.
how to create simple calculator in oracle pl sql developer
i m a student and i wanna know how to create simple calculator in pl sql developer please share query .. or recommend the exact website where i can find
how to write a stored procedure to insert the employee details in a table
conditions: write it for one month,30 days will be displayed,holidays dates will be skipped.
Write a plsql code, which takes two numbers and operator as input from user
and then apply that operator on given number. (use arithmetic operator +,-, /,*).
Thank you sir
How to add 2 numbers without using + operator in PL/SQL