mysql中的hex函数_MySQL中HEX函数的用法

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 |

+---------------+

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值