Hexadecimal literals
Hexadecimal literals can be written using any of the following syntaxes:
- x'
value
' - X'
value
' (SQL standard) - 0x
value
(ODBC)
value
is a sequence of hexadecimal digits (from 0
to 9
and from A
to F
). The case of the digits does not matter. With the first two syntaxes, value
must consist of an even number of digits. With the last syntax, digits can be even, and they are treated as if they had an extra 0 at the beginning.
Normally, hexadecimal literals are interpreted as bunary string, where each pair of digits represents a character. When used in a numberic context, they are interpreted as integers. In no case an hexadecimal literal can be a decimal number.
Examples
Representing the a
character with the three syntaxes explained above:
SELECT x'61', X'61', 0x61; +-------+-------+------+ | x'61' | X'61' | 0x61 | +-------+-------+------+ | a | a | a | +-------+-------+------+
Hexadecimal literals in a numeric context:
SELECT 0 + 0xF, -0xF; +---------+------+ | 0 + 0xF | -0xF | +---------+------+ | 15 | -15 | +---------+------+