Literals
Literals come in the following varieties:
- String literals
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:
'Thisisa''quote'''. However, you do not need to double up on single quotes when the string is enclosed by double quotes:"Thisisa'quote'".- Binary literals
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).- Number literals
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.- Hexadecimal literals
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.- Null
The special keyword
NULLsignifies a null literal ...
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