Declaring a variable v15
Generally, you must declare all variables used in a block in the declaration section of the block. A variable declaration consists of a name that's assigned to the variable and its data type. Optionally, you can initialize the variable 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 isn't 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.
This procedure shows some variable declarations that use defaults consisting of string and numeric expressions:
The following output of the procedure shows that default values in the variable declarations are assigned to the variables: