PLSQL

PL/SQL Variables

PL/SQL Variables

A variable is the name given to a storage area that our programs can manipulate. Each variable in PL/SQL has a specific data type, that determines the size and also the layout of the variable’s memory and the range of values that can be stored within that memory and the set of operations that also can be applied to the variable.

The name of a PL/SQL variables consists of a letter optionally followed by more letters, numerals, dollar signs, underscores and number signs and should not exceed 30 characters. These variables are not case sensitive by default. We cannot use a reserved PL/SQL keyword as a variable name. this programming language allows us to define various types of variables, such as data time data types, records, collections, etc.

Variable declaration in PL/SQL.

These variables must be declared in the declaration section or in the package as a global variable. When we declare a variable, PL/SQL allocates memory for the Variable’s value and the storage location is identified by the variable name.

Syntax for declaring the variable is:

Variable_name [CONSTANT] datatype [NOT NULL] [:= | DEFAULT initial_value]

We can say that variable_name is a valid identifier in PL/SQL, data type must be a valid PL/SQL data type or else any used defined data type.

Example:

Marks number (10,2)

pi CONSTANT double precision := 3.141.5;

name varchar2(20);

address varcgar2(100);

whenever we provide a size, scale or the precision limit with the data type, is said to be known as a constrained declaration. These declarations require less memory than unconstrained declaration. Like the example given below:

Marks number (10,2)

name varchar2(20);

address varchar2(100);