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: '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'".

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 NULL signifies a null literal in SQL. In the context of import files, the special escape sequence N signifies a null value.

Table 15-1. MySQL escape sequences

Escape Sequence

Value

NUL

'

Single quote

"

Double quote



Backspace

Newline

Carriage return

Tab

z

Ctrl-z (workaround for Windows use of Ctrl-z as EOF)

\

Backslash

\%

Percent sign (only in contexts where a percent sign would be interpreted as a wildcard)

\_

Underscore (only in contexts where an underscore would be interpreted as a wildcard)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset