Literals come in the following varieties:
String
literals may be enclosed either by single or double quotes. If you
wish to be ANSI compatible, you should always use single quotes.
Within a string literal, you may represent special characters through
escape sequences. An escape sequence is a backslash followed by
another character to indicate to MySQL that the second character has
a meaning other than its normal meaning. Table 15-1
shows the MySQL escape sequences. Quotes can also be escaped by
doubling them up: 'This
is
a
''quote'''
. However, you do
not need to double up on single quotes when the string is enclosed by
double quotes: "This
is
a
'quote'"
.
Like
string literals, binary literals are enclosed in single or double
quotes. You must use escape sequences in binary data to escape
NUL
(ASCII 0), "
(ASCII 34),
'
(ASCII 39), and (ASCII 92).
Numbers appear as a sequence of digits.
Negative numbers are preceded by a -
sign and a
.
indicates a decimal point. You may also use
scientific notation, as in: -45198.2164e+10.
MySQL also supports the use of hexadecimal
literals in SQL. The way in which that hexadecimal is interpreted is
dependent on the context. In a numeric context, the hexadecimal
literal is treated is a numeric value. In a non-numeric context, it
is treated as a binary value. For example, 0x1 + 1 is 2, but
0x4d7953514c by itself is MySQL
.
The special keyword NULL
signifies a null literal in SQL. In the context of import files, the
special escape sequence N
signifies a null value.