Literals in pl/sql, PL-SQL Programming


A literal is an explicit numeric, string, character, or Boolean value not represented by an identifier. Numeric literal 147 and the Boolean literal FALSE are some of the examples.

Numeric Literals

The 2 kinds of numeric literals can be used in an arithmetic expression: integers & reals. The  integer literal is an optionally signed whole number without a decimal point. Some of the examples are shown below:

030, 6, -14, 0, +32767

A real literal is an optionally signed whole or fractional number with a decimal point. Some of the examples are shown below:

6.6667, 0.0, -12.0, 3.14,159, +8300.0, 0 .5 25

The PL/SQL considers numbers like 12.0 and 25. to be real even if they have integral values.

The Numeric literals cannot contain dollar signs or commas, however can be written using the scientific notation. Just suffix the number with an E (or e) followed by an optionally signed integer. A few examples are shown below:

2E5 1.0E-7 3.14159e0 -1E38 -9.5e-3

The E stands for "times ten to the power of." As the next illustration represents, the number after E is the power of ten by which the number before E must be multiplied (the double asterisk (**) is the exponentiation operator):

5E3 = 5 10**3 = 5 1000 = 5000

The number after E also correspond to the number of places the decimal point shift. In the last illustration, the implicit decimal point shifted three places to the right. In this illustration, it shifts three places to the left:

5E-3 = 5 10**-3 = 5 0.001 = 0.005

As the example below shows, if the value of a numeric literal falls outside the range 1E-130... 10E125, you obtain a compilation error:




n := 10E127; -- causes a 'numeric overflow or underflow' error

Character Literals

A character literal is an individual character enclosed by single quotes (apostrophes). The Character literals include all the printable characters in the PL/SQL character set: numerals, letters, spaces, and special symbols. Some examples are as shown:

'Z' '%' '7' ' ' 'z' '('

The PL/SQL is case sensitive within the character literals. For example, PL/SQL considers

the literals 'Z' and 'z' to be different. Also the character literals '0'..'9' are not equivalent to the integer literals but can be used in the arithmetic expressions as they are implicitly convertible to integers.

String Literals

A character value can be represented by an identifier or explicitly written as a string literal that is a sequence of zero or more characters enclosed by single quotes. Several examples are shown below:

'Hello, world!'

'XYZ Corporation'


'He said "Life is like licking honey from a thorn."'


All the string literals except the null string ('') have datatype CHAR. Given that the apostrophes (single quotes) delimit string literals, how do you show an apostrophe within a string? As the next illustration shows, you write two single quotes that are not similar as writing a double quote:

"'Don't leave without saving the work."

The PL/SQL is case sensitive within string literals. For illustration, PL/SQL considers the following literals to be different:



Boolean Literals

The Boolean literals are the predefined values TRUE, FALSE, & NULL (which stand for an unknown, missing, or inapplicable value). Keep in mind; the Boolean literals are values, and not the strings. For illustration, TRUE is no less a value than the number 25.

Posted Date: 10/2/2012 2:07:10 AM | Location : United States

Related Discussions:- Literals in pl/sql, Assignment Help, Ask Question on Literals in pl/sql, Get Answer, Expert's Help, Literals in pl/sql Discussions

Write discussion on Literals in pl/sql
Your posts are moderated
Related Questions
SELECT a.child_fname,a.child_lname,concat(b.parent_title,b.parent_fname), b.parent_lname,b.parent_tphone FROM child a,parent b WHERE a.parent_id=b.parent_id ORDER BY a.child_fnam

Renaming Columns - SQL SQL has no direct counterpart of RENAME. To derive the table on the right in Figure 4.4 from the table on the left, Tutorial D has IS_CALLED RENAME ( St

Closing a Cursor The CLOSE statements disable the cursor, and the result set becomes undefined. An illustration of the CLOSE statement as shown: CLOSE c1;

Using Subqueries A subquery is a query (typically enclosed by parentheses) that appears within another SQL data manipulation statement. If evaluated, the subquery gives a va

Application to Export Excel Data to MSSQL Server table I am having a table available in excel format and features the subsequent: - Some text is in Arabic (e.g. UTF-8 encodin

Organi c Evolution Evolution is a slow continuous, irreversible and natural process of change to give rise to advance and diverse forms of life i.e. formation of new specie

SQL outer join SELECT * FROM IS_CALLED NATURAL LEFT JOIN IS_ENROLLED_ON Note that adding LEFT to an invocation of CROSS JOIN has no effect unless the right-hand operand

EXCEPTION_INIT Pragma The pragma EXCEPTION_INIT relates an exception name with an Oracle error number. Which allow you to refer to any internal exception by the name and to wri

Predicate - SQL Consider the declarative sentence-a proposition-that is used to introduce this topic:  "Student S1, named Anne, is enrolled on course C1." Recall that th

Parameter Modes   To define the behavior of formal parameters you use the parameter modes. The 3 parameter modes, IN, OUT, & IN OUT, can be used with any subprogram. Though, a