PL/SQL block to define Variable

Variables and Constants in PL/SQL

  • A variable is a meaningful name that provides facility for programmer to store data temporary during execution of code. It helps to manipulate data in PL/SQL.
  • A constant is a value used in PL/SQL block that remains unchanged throughout the program and it can be declared and used instead of actual values.
Q. Write a PL/SQL block to define Variable (adding two numbers).

The following program describes, how to define a variable by adding two numbers.

Declare
Var1 integer;
Var2 integer;
Var3 integer;
Begin
Var1:=&var1;
Var2:=&var2;
Var3:=var1+var2;
Dbms_output.put_line(var3);
End;
/


Note: PL/SQL block can be nested within other PL/SQL blocks with the help of BEGIN and END keyword. The code starts with DECLARE and it is used to define all variables, cursors, subprograms and other elements which can be used in the program.

Output:

define variable