MySQL Tutorial/Data Types/hexadecimal

Материал из SQL эксперт
Версия от 09:53, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Convert a string or a number to a string in hexadecimal format with the HEX() function

mysql>
mysql> SELECT HEX("cat");
+------------+
| HEX("cat") |
+------------+
| 636174     |
+------------+
1 row in set (0.02 sec)
mysql>
mysql> SELECT 0x636174;
+----------+
| 0x636174 |
+----------+
| cat      |
+----------+
1 row in set (0.00 sec)
mysql>


How 0x00-padding of BINARY values affects column value comparisons:

mysql>
mysql> CREATE TABLE myTable (c BINARY(3));
Query OK, 0 rows affected (0.03 sec)
mysql>
mysql> INSERT INTO myTable SET c = "a";
Query OK, 1 row affected (0.00 sec)
mysql>
mysql> SELECT HEX(c), c = "a", c = "a\0\0" from myTable;
+--------+---------+-------------+
| HEX(c) | c = "a" | c = "a\0\0" |
+--------+---------+-------------+
| 610000 |       0 |           1 |
+--------+---------+-------------+
1 row in set (0.00 sec)
mysql>
mysql> drop table myTable;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql>


SELECT 0x5162766c;

mysql>
mysql>
mysql> SELECT 0x5162766c;
+------------+
| 0x5162766c |
+------------+
| Qbvl       |
+------------+
1 row in set (0.00 sec)
mysql>


SELECT 0xa+0;

mysql>
mysql>
mysql>
mysql> SELECT 0xa+0;
+-------+
| 0xa+0 |
+-------+
|    10 |
+-------+
1 row in set (0.00 sec)


The default type of a hexadecimal value is a string

mysql>
mysql> SELECT 0x41, CAST(0x41 AS UNSIGNED);
+------+------------------------+
| 0x41 | CAST(0x41 AS UNSIGNED) |
+------+------------------------+
| A    |                     65 |
+------+------------------------+
1 row in set (0.00 sec)