The general syntax is <Variable name><type> [:=<value];
Example: pay NUMBER(6,2);
name VARCHAR2 (30);
Assigning a value to a variable
A value can be assigned to the variable in any one of the following two ways.
- Using the assignment operator :=
Pay := basic +da.
- Selecting or fetching table data values in to variables.
Declaring a constant
Declaring a constant is similar to declaring a variable except that you have to add the key word CONSTANT and immediately assign a value to it. Thereafter, no further assignment to the constant is possible.
Example: pf_percent CONSTANT NUMBER (3,2):=8.33;
An Identifier in PL/SQL block
The name of any ORACLE object (variable, memory variable, constant, record, cursor etc) is known as an Identifier. The following laws have to be followed while working with identifiers.
- An identifier cannot be declared twice in the same block
- The same identifier can be declared in two different blocks