PL/SQL Program To Add Two Numbers

In the previous tutorial we have learnt much about PL/SQL variables, operators, data types and other such fundamental topics. Let us get into real programming now onwards.

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


PL/SQL Program To Add Two Numbers

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.

This statement assigns the value that the user enters for the variable. Similarly, we have taken input for next variable.

This statement is used to assign the calculated values of Var1 and Var2 into the third variable.

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.

6 thoughts on “PL/SQL Program To Add Two Numbers

  1. Manish Pandey

    hii…thank you it was very helpful
    can you explain how to find largest of 2/3 numbers?

  2. Ronikarajalakshmi

    hello, please put on algorithm steps from program codings in pL/SQL


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.