Hexadecimal Literals
750
• As a number in
HHMMSS
format, provided that it makes sense as a time. For example,
101112
is
understood as
'10:11:12'
. The following alternative formats are also understood:
SS
,
MMSS
, or
HHMMSS
.
A trailing fractional seconds part is recognized in the
'D HH:MM:SS.fraction'
,
'HH:MM:SS.fraction'
,
'HHMMSS.fraction'
, and
HHMMSS.fraction
time formats, where
fraction
is the fractional part in up to microseconds (6 digits) precision. Although this fractional part
is recognized, it is discarded from values stored into
TIME
columns. For information about fractional
seconds support in MySQL, see
Section 11.1.5.6, “Fractional Seconds in Time Values”
.
For
TIME
values specified as strings that include a time part delimiter, it is unnecessary to specify
two digits for hours, minutes, or seconds values that are less than
10
.
'8:3:2'
is the same as
'08:03:02'
.
9.1.4. Hexadecimal Literals
MySQL supports hexadecimal values, written using
X'val'
,
x'val'
, or
0xval
format, where
val
contains hexadecimal digits (
0..9
,
A..F
). Lettercase of the digits does not matter. For values written
using
X'val'
or
x'val'
format,
val
must contain an even number of digits. For values written using
0xval syntax
, values that contain an odd number of digits are treated as having an extra leading
0
.
For example,
0x0a
and
0xaaa
are interpreted as
0x0a
and
0x0aaa
.
In numeric contexts, hexadecimal values act like integers (64-bit precision). In string contexts, they act
like binary strings, where each pair of hex digits is converted to a character:
mysql>
SELECT X'4D7953514C';
-> 'MySQL'
mysql>
SELECT 0x0a+0;
-> 10
mysql>
SELECT 0x5061756c;
-> 'Paul'
The default type of a hexadecimal value is a string. If you want to ensure that the value is treated as a
number, you can use
CAST(... AS UNSIGNED)
[948]
:
mysql>
SELECT 0x41, CAST(0x41 AS UNSIGNED);
-> 'A', 65
The
X'hexstring'
syntax is based on standard SQL. The
0x
syntax is based on ODBC.
Hexadecimal strings are often used by ODBC to supply values for
BLOB
columns.
You can convert a string or a number to a string in hexadecimal format with the
HEX()
[889]
function:
mysql>
SELECT HEX('cat');
-> '636174'
mysql>
SELECT 0x636174;
-> 'cat'
9.1.5. Boolean Literals
The constants
TRUE
and
FALSE
evaluate to
1
and
0
, respectively. The constant names can be written
in any lettercase.
mysql>
SELECT TRUE, true, FALSE, false;
-> 1, 1, 0, 0
9.1.6. Bit-Field Literals
Beginning with MySQL 5.0.3, bit-field values can be written using
b'value'
or
0bvalue
notation.
value
is a binary value written using zeros and ones.
Bit-field notation is convenient for specifying values to be assigned to
BIT
columns:
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...