Monday, February 11, 2013

PL/SQL Constants


As the name implies a constant is a value used in a PL/SQL Block that remains unchanged throughout the program. A constant is a user-defined literal value. You can declare a constant and use it instead of actual value.

For example: If you want to write a program which will increase the salary of the employees by 25%, you can declare a constant and use it throughout the program. Next time when you want to increase the salary again you can change the value of the constant which will be easier than changing the actual value throughout the program.
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; 


5 comments:

  1. Thanks for the Great article with important information!. I think your Blog is useful for the beginner level. But I had found one good and effective E-learning website related to PL SQL. I have gone through the website. It’s easy and effective for both beginner as well as advanced level. If you are interested in PL SQL just have a look: https://goo.gl/M7nIKj

    ReplyDelete
  2. Nice article post..
    http://www.informaticaonlinetraining.co/

    ReplyDelete
  3. Thanks for sharing the valuable information here. So i think i got some useful information with this content. Thank you and please keep update like this informative details.

    Best Dental Clinic In Vellore

    Best Dental Clinic In OMR

    ReplyDelete
  4. This idea is mind blowing. I think everyone should know such information like you have described on this post. Thank you for sharing this explanation.Your final conclusion was good. We are sowing seeds and need to be patiently wait till it blossoms.
    Psoriasis Shampoo
    Best Anti Dandruff Shampoo
    Psoriasis Scalp Treatment
    Dandruff Shampoo

    ReplyDelete

Thank you :
- kareem