A variable is a container that stores value or information.
Syntax:
variable_Name [ CONSTANT ] datatype [ NOT NULL] [:= | DEFAULT Initial_Value | expression];
some of the components of the syntax are optional.
Variable_Name: this is the name of the variable. While it can be anything (must be valid), it's advisable to use meaningful names. The variable 'student_name' is
betther than just 's'. There are all valid variable names.
CONSTANT: this is optional and should be used if the variable value does not be changed in the future.
datatype: this defines the datatype of the variable. It can be a NUMBER or character datatype for example.
NOT NULL: it is optional. If not null, then a value must assigned to the variable.
:= this is the assignment operator in PL SQL
DEFAULT initial value: is the initial value assignment to the variable. It can be boolean, number, null or character.
Variable Naming Convention
Here are some rules to observe when naming variables in PL SQL:
- Must start with a number
- Can contain special characters like _, #, $
- Maximum length of 30 characters
- Not an Oracle reserved word.