Looking for a Tutor Near You?

Post Learning Requirement »
x

Choose Country Code

x

Direction

x

Ask a Question

x

x
x
x
Hire a Tutor

ORACLE PLSQL - Constants And Literals

Loading...

Published in: Oracle Training
1,299 Views

This document discuss constants and literals in PL/SQL.

Debarun S / Kolkata

10 years of teaching experience

Qualification: B.Tech

Teaches: Computer, Mathematics, Science, Chemistry, Computer Science, Physics, School Level Computer, Defence Exams, IBPS, Insurance Exams, SSC Exams

Contact this Tutor
  1. In this chapter, we will discuss constants and literals in PL/SQL. A constant holds a value that once declared, does not change in the program. A constant declaration specifies its name, data type, and value, and allocates storage for it. The declaration can also impose the NOT NULL constraint. Declaring a Constant A constant is declared using the CONSTANT keyword. It requires an initial value and does not allow that value to be changed. For example PI CONSTANT NUMBER DECLARE 3.141592654; constant declaration pi constant number 3.141592654; other declarations radius number (5, 2) dia number (5, 2) circumference number (7, area number (10, 2) BEGIN processing radius 9.5; dia radius * 2 • 2); circumference radius radius; output Il radius) dbms output. put line( ' Radius: dbms output. put line ( 'Diameter: Il dia), dbms output . put line ( 'Circumference: ci rcumference ) dbms output. put line( 'Area: END; When the above code is executed at the SQL prompt, it produces the following result Radius : 9.5 Diameter: 19 Circumference : Area: 283.53 59.69 PI/ SQL procedure successfully completed. The PL/SQL Literals A literal is an explicit numeric, character, string, or Boolean value not represented by an identifier. For example, TRUE, 786, NULL, 'tutorialspoint' are all literals of type Boolean, number, or string. PL/SQL, literals are case-sensitive. PL/SQL supports the following kinds of literals Numeric Literals
  2. Character Literals String Literals BOOLEAN Literals Date and Time Literals The following table provides examples from all these categories of literal values. S.N0 1 2 3 4 5 Literal Type & Example Numeric Literals 050 78 -14 0 +32767 6.6667 0.0 -12.0 3.14159 +7800.00 6E5 1.OE-8 3.14159eo -IE38 -9.5e-3 Character Literals String Literals 'Hello, world!' 'Tutorials Point' '19-NOV-12' BOOLEAN Literals TRUE, FALSE, and NULL. Date and Time Literals DATE '1978-12-25'; TIMESTAMP '2012-10-29 To embed single quotes within a string literal, place two single quotes next to each other as shown in the following program DECLARE message varchar2 (30) BEGIN That ' s tutorialspoint.com! dbms output. put line (message) END; When the above code is executed at the SQL prompt, it produces the following result
  3. That's tutorialspoint.com! P L/ SQL procedure successfully completed.