Literals
SQL evaluates literal values as any explicit numeric, character string, temporal value (like a 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 the example illustrates, SQL Server allows signed or 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), so do not include commas (or periods in Europe). Most databases interpret a comma in a numeric literal as a list item separator. Thus, the literal value 3,000 would be interpreted by the database as 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 by single quotation marks (' '), the standard delimiter for all character string literals. Character string literals are not restricted just to the alphabet. In fact, any character in the character set can be represented as a string literal. All of the following are string literals:
'1998' '70,000 + 14000' 'There once was a man from Nantucket,' ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access