CodesJava

Easy learning with example program codes

Oracle pl sql constants and literals tutorial


PL/SQL Constants:

A constant holds a value used in a PL/SQL block that does not change throughout the program. It is a user-defined literal value.

Syntax to declare a constant:

constant_name CONSTANT datatype := VALUE;

Where:

constant_name – is a valid identifier name.
CONSTANT – is a keyword.
VALUE – is a value which must be assigned to a constant when it is declared. You cannot assign a value later.

Example:

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 := 10.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;
/

Output:

Radius: 10.5
Diameter: 21
Circumference: 65.97
Area: 346.36

PL/SQL Literals:

Literals is an explicit numeric, character, string or Boolean values which are not represented by identifiers i.e. TRUE, NULL, tutorialspointexamples etc.
Note: PL/SQL literals are case-sensitive.

Types of literals in PL/SQL:

1. Numeric Literals (765, 23.56 etc.).
2. Character Literals (‘A’ ‘%’ ‘9’ ‘ ‘ ‘z’ etc.).
3. String Literals (tutorialspointexamples.com etc.).
4. BOOLEAN Literals (TRUE, FALSE and NULL).
5. Date and Time Literals (‘2016-12-25’ ‘2016-02-03 12:10:01’ etc.).
 



Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki