Literals

A literal is a value that is not represented by an identifier; it is simply a value. A literal may be composed of one of the following types of data:

Number

415, 21.6, or NULL

String

`This is my sentence’ or `01-FEB-2003’ or NULL

Boolean

TRUE, FALSE, or NULL

Notice that there is no direct way to code a true date literal. The value `01-FEB-2003’ is a string literal (any sequence of characters enclosed by single quotes). You can convert such a string to a date in PL/SQL or SQL, but a date has only an internal binary representation in Oracle.

A string literal can be composed of zero or more characters from the PL/SQL character set. A literal of zero characters is represented as '' (two consecutive single quotes with no characters between them). At least through Oracle9i, this zero-length string literal has the value NULL,[10] and a datatype of CHAR (fixed-length string).

Unlike identifiers, string literals in PL/SQL arecase-sensitive. The following two literals are different:

'Steven'
'steven'

The following condition, for example, evaluates to FALSE:

IF 'Steven' = 'steven'

Embedding Single Quotes Inside a String

The trickiest part of working with string literals comes when you need to include a single quote inside a string literal (as part of the literal itself). Generally, the rule is that you write two single quotes next to each other inside a string if you want the literal to contain a single quote in that position. The following table shows the literal in one column ...

Get Oracle PL/SQL Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.