【问题标题】:Convert a character string of hexadecimal digits into bigint?将十六进制数字的字符串转换为bigint?
【发布时间】:2021-02-27 09:08:57
【问题描述】:

我有一张这样的桌子:

create table valid_device (
  id char(8) not null default '' comment 'id',
  begin char(24) not null comment 'device id that is valid begin',
  end char(24) comment 'device id that is valid end',
  primary key (id)
) engine=innodb default charset=utf8mb4 comment='valid device';

如果我写:

没关系。 但如果我写: 这不是我想要的。

如果我使用 CONV('AAAAAAAAAAAAAAAAAAAAAAAB', 16, 10) 会导致 bigint 溢出? 我该怎么办? 非常感谢!

【问题讨论】:

    标签: mysql sql type-conversion overflow bigint


    【解决方案1】:

    如果我使用 CONV('AAAAAAAAAAAAAAAAAAAAAAAB', 16, 10) 会导致 bigint 溢出?

    当然。

    我该怎么办?

    如果您需要检查一个值是否在beginend 之间,那么您可以使用字符串比较,其中所有值都被标准化为相同的长度。

    对于匹配的值 CHAR(24) 使用 LPAD(TRIM(value), @length, '0') 其中整数 @length 是 24 或更大。

    【讨论】:

      猜你喜欢
      • 2018-01-31
      • 1970-01-01
      • 2014-03-19
      • 2013-02-07
      • 2018-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多