Learn PL/SQL Language

A block structured language that can have multiple blocks in it. Our tutorial includes all topics of PL/SQL language.

PL/SQL Introduction
Control Statements
PLSQL Concepts

Constants in PL/SQL

A constant is a value used in a PL/SQL block that remains unchanged throughout the program. It is a user-defined literal value. It can be declared and used instead of actual values.

Let's take an example :

constant_name CONSTANT datatype := VALUE;

Constant_name : It is the name of constant just like variable name. The constant word is a reserved word and its value does not change.

VALUE : it is a value which is assigned to a constant when it is declared. It can not be assigned later.

    DECLARE  
    -- constant declaration  
    pi constant number := 3.141592654;  
    -- other declarations  
    radius number(5,2);   
    dia number(5,2);   
    circumference number(7, 2);  
    area number (10, 2);  
 BEGIN   
    -- processing  
    radius := 9.5;   
    dia := radius * 2;   
    circumference := 2.0 * pi * radius;  
    area := pi * radius * radius;  
    -- output  
    dbms_output.put_line('Radius: ' || radius);  
    dbms_output.put_line('Diameter: ' || dia);  
    dbms_output.put_line('Circumference: ' || circumference);  
    dbms_output.put_line('Area: ' || area);  
 END;  

After the execution, this will produce the following result:

Now that you know constants in PL/SQL, let's jump to conditionals Statements in PL/SQL


Share this page on :