Literals

SQL defines a literal value as any explicit numeric value, character string, temporal value (e.g., date or time), or Boolean value that is not an identifier or a keyword. SQL databases allow a variety of literal values in a SQL program. Literal values are allowed for most of the numeric, character, Boolean, and date datatypes. For example, SQL Server numeric datatypes include (among others) INTEGER, REAL, and MONEY. Thus, numeric literals can look like:

30
−117
+883.3338
−6.66
$70000
2E5
7E-3

As these examples illustrate, SQL Server allows signed and unsigned numerals, in scientific or normal notation. And since SQL Server has a money datatype, even a dollar sign can be included. SQL Server does not allow other symbols in numeric literals (besides 0 1 2 3 4 5 6 7 8 9 + - $ . E e), however, so do not include commas (or periods, in European countries where a comma is used in place of a period in decimal or monetary values). Most databases interpret a comma in a numeric literal as a list item separator. Thus, the literal value 3,000 would likely be interpreted as two values: 3 and, separately, 000.

Boolean, character string, and date literals look like:

TRUE
'Hello world!'
'OCT-28-1966 22:14:30:00'

Character string literals should always be enclosed in single quotation marks (''). This is the standard delimiter for all character string literals. Character string literals are not restricted just to the letters of the alphabet. In fact, any character in the character set can be represented ...

Get SQL in a Nutshell, 3rd 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.