Declaring a Variable v11
Generally, all variables used in a block must be declared in the declaration section of the block. A variable declaration consists of a name that is assigned to the variable and its data type. Optionally, the variable can be initialized to a default value in the variable declaration.
The general syntax of a variable declaration is:
name
is an identifier assigned to the variable.
type
is the data type assigned to the variable.
[ := expression ]
, if given, specifies the initial value assigned to the variable when the block is entered. If the clause is not given then the variable is initialized to the SQL NULL
value.
The default value is evaluated every time the block is entered. So, for example, assigning SYSDATE
to a variable of type DATE
causes the variable to have the time of the current invocation, not the time when the procedure or function was precompiled.
The following procedure illustrates some variable declarations that utilize defaults consisting of string and numeric expressions.
The following output of the above procedure shows that default values in the variable declarations are indeed assigned to the variables.