Variables in Oracle PL/SQL - Part 1

In this PL/SQL Tutorial post, We will explore about the variables in Oracle PL/SQL.

Variables in Oracle PL/SQL - Part 1

In this session, We will take some questions which is related to variables and then we will share answers which will help to understand more about the variables in Oracle PL/SQL.

What is Variables in Oracle PL/SQL?

Variables is just a simple named block of the memory.


Variables is name of the storage location in memory.

We will share a diagram to you for the better understanding and you can also relate with meaning of Variables in Oracle PL/SQL.

What is syntax of variables in  Oracle PL/SQL?

variable_name [constant] data_type [not null] [:=|default value initial_value|];

Now, we are explaining syntax of variables in detail with the example.

As you can see the above syntax of variables, That keyword in the brackets are optional in variable declaration.

Declaration of Variable in Oracle PL/SQL

v_name varchar2(100);

As you can see that, I am  taking a simple variable with varchar2 data type. Now we will tell you that how can we use above variable in the PL/SQL program. Let given an simple example.

As we know that, PL/SQL program only needed to execution section but if you needed to define or declare any variables then you have to added declaration section.

Now I am writing an anonymous block to create a variables. If you have not know about the anonymous block then click here.

v_name varchar2(100);
v_name:='Javainhand Tutorial';

After the execute the above program, You will be see the output Javainhand Tutorial.(If output not display in your environment then please run set serveroutput on command).

Following Rules follow while creating Variables in PL/SQL Program

  1. Variables Name should not contain more than 30 characters.
  2. Variables Name should not start with the numeric values like (1 test).
  3. Variables Name should not contain special characters like (.@#$) etc.
  4. Variables Name should not contain spaces like (t name).

That's all for today,  this post may be help to you for the understanding about the (What is Variables in PL/SQL?).

In the Next tutorial, we will cover rest of the variables keyword. Just like constant,Not Null, Assigning the value with default keyword and using assignment operator.

Post a Comment