Constant Syntax

The General Syntax to declare a constant is:
constant_name CONSTANT datatype := VALUE; 
  • constant_name is the name of the constant i.e. similar to a variable name.
  • The word CONSTANT  is a reserved word and ensures that the value does not change.
  • VALUE - It is a value which must be assigned to a constant when it is declared. You cannot assign a value later.
For example, to declare salary_increase, you can write code as follows:
 
DECLARE 
salary_increase CONSTANT number (3) := 10; 
 
You must assign a value to a constant at the time you declare it. If you do not assign a value to a constant while declaring it and try to assign a value in the execution section, you will get a error. If you execute the below Pl/SQL block you will get error.

DECLARE 
 salary_increase CONSTANT number(3); 
BEGIN 
 salary_increase := 100; 
 dbms_output.put_line (salary_increase); 
END; 
 
 

No comments:

Post a Comment