Definition:
- Constants are user defined identifier whose values remain unchanged throughout the program
- Constants needs to be declared prior to their use like variables in PL/SQL
- Constants can declared only in the declaration section in the PL/SQL block.
Syntax:
Explanation:
- Constant_name valid constant name (user defined)
- Constant_name followed CONSTANT keyword
- Data_type of the value
- := Assignment operator
- Value (constant value)
Note:
You must initialize the constant at the DECLARATION section. You cannot
initialize the constant anywhere else.
Example:
Output:
Attributes of constants:
1. Default
2. Not
Null
Default:
Here, we are used DEFAULT keyword Instead of assignment operator (:=) for initializing the constant.
Output:
Not Null:
NOT NULL for preventing Null values.
Output:
Example for Initialize constant in the BEGIN section:
Explanation:
Above type of declaration and initialization is legally accepted in PL/SQL variable but comes to constant this is not accepted by the compiler.
The error report
is,
No comments:
Post a Comment