MySQL5.5官方参考文档:
HEX(N_or_S)
If N_or_S is a number, returns a string representation of the hexadecimal value of N, where N is a longlong (BIGINT) number. This is equivalent to CONV(N,10,16).
If N_or_S is a string, returns a hexadecimal string representation of N_or_S where each character in N_or_S is converted to two hexadecimal digits. The inverse of this operation is performed by the UNHEX() function.
mysql> SELECT HEX(255);
-> 'FF'
mysql> SELECT 0x616263;
-> 'abc'
mysql> SELECT HEX('abc');
-> 616263
1.HEX(number),如果number不是整数,则在进行运算前将其四舍五入为最接近的整数,然后返回该数的十六进制数值表示形式;
mysql> SELECT HEX(12.34);
+------------+
| HEX(12.34) |
+------------+
| C |
+------------+
1 row in set (0.00 sec)
mysql> SELECT HEX(12.54);
+------------+
| HEX(12.54) |
+------------+
| D |
+------------+
1 row in set (0.00 sec)
2.如果number是NULL,将返回NULL值;
mysql> SELECT HEX(NULL);
+-----------+
| HEX(NULL) |
+-----------+
| NULL |
+-----------+
1 row in set (0.00 sec)
3.如果number是一个字符串,则返回number的十六进制字符串表示形式,其中number里的每个字符被转化为两个十六进制数字:
mysql> SELECT HEX('abc');
+------------+
| HEX('abc') |
+------------+
| 616263 |
+------------+
1 row in set (0.00 sec)
mysql> SELECT HEX('a');
+----------+
| HEX('a') |
+----------+
| 61 |
+----------+
1 row in set (0.00 sec)
mysql> SELECT HEX('我爱你');
+---------------+
| HEX('我爱你') |
+---------------+
| CED2B0AEC4E3 |
+---------------+