Sum Of Two Numbers in PL/SQL
Prerequisite – PL/SQL introduction
In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements.
In declare part, we declare variables and between begin and end part, we perform the operations.
Here, first, we take three variables x, y, and z and assign the value in x and y and after addition of both the numbers, we assign the resultant value to z and print z.
Examples:
Input : 15 25 Output : 40
Input : 250 400 Output : 650
Below is the required implementation:
declare -- declare variable x, y -- and z of datatype number x number(5); y number(5); z number(7); begin -- Here we Assigning 10 into x x:=10; -- Assigning 20 into x y:=20; -- Assigning sum of x and y into z z:=x+y; // Print the Result dbms_output.put_line('Sum is '||z); end; / -- Program End |
Output :
Sum is 30
Recommended Posts:
- Comparisons between SQL vs PLSQL
- GCD of two numbers in PL/SQL
- Print all even numbers from 1 to n in PL/SQL
- Print all odd numbers and their sum from 1 to n in PL/SQL
- Sum and average of three numbers in PL/SQL
- Swap two numbers in PL/SQL
- Swap two numbers in PL/SQL without using temp
- Finding sum of first n natural numbers in PL/SQL
- Convert the given numbers into words in Pl/SQL
- Greatest number among three given numbers in PL/SQL
- Display Sequence of Numbers in SQL Using LEVEL
- Neo4j Introduction
- SELECT INTO statement in SQL
- Extendible Hashing | A Dynamic approach to DBMS
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



