Sum Of Two Numbers in PL/SQL Last Updated : 05 Apr, 2024 Comments Improve Suggest changes Like Article Like Report Prerequisite - PL/SQL introductionIn 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: Method 1: SQL 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 Method 2(Using function) : Here we are giving input during run time: SQL CREATE OR REPLACE FUNCTION add_two_nums( num1 NUMERIC, num2 NUMERIC ) RETURNS NUMERIC AS $$ BEGIN RETURN num1 + num2; END; $$ LANGUAGE PLPGSQL; In this method, we've created a PL/pgSQL function named 'add_two_nums' that takes two 'NUMERIC' parameters ('num1' and 'num2') and returns their sum. You can use the function like this: postgres=# SELECT add_two_nums(5,6);Output: 11 Comment More infoAdvertise with us Next Article Swap two numbers in PL/SQL S Sriram Pandey Follow Improve Article Tags : PL/SQL SQL-PL/SQL Similar Reads GCD 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. Given two numbers and task is to find the GCD (Greatest 1 min read GCD 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. Given two numbers and task is to find the GCD (Greatest 1 min read Swap two numbers in PL/SQL 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. Basic structure of pl/sql block declare -- declare all the variables begin -- for start bl 1 min read Sum and average of three 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. Given three numbers and the task is to find out the sum 2 min read Sum and average of three 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. Given three numbers and the task is to find out the sum 2 min read Sum of digits of a number 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. Given a number and task is to find the sum of digits of 1 min read Like