美好的一天!
我有一个表T1(在MariaDB)与二进制列C1。它有一些字节。
当我选择HEX时,我有以下内容:
select HEX(SUBSTRING((select C1 from T1 where <some restrictions>), 254, 2));
+----------------------------------------------------------------------+
| HEX(SUBSTRING((select C1 from T1 where <some restrictions>), 254, 2)) |
+----------------------------------------------------------------------+
| 1200 |
+----------------------------------------------------------------------+
但我未能将结果转换为INT:
select cast((SUBSTRING((select C1 from T1 where <some restrictions>), 254, 2)) as int);
+--------------------------------------------------------------------------------+
| cast((SUBSTRING((select C1 from T1 where <some restrictions>), 254, 2)) as int) |
+--------------------------------------------------------------------------------+
| 0 |
+--------------------------------------------------------------------------------+
所以,我的问题是 - 为什么会发生这种情况,如何将二进制转换为int?
答案 0 :(得分:0)
类型有:无符号整数或有符号整数
select cast((substring((select C1 from T1 where <some restrictions>), 254, 2)) as unsigned integer);
select cast(substring( '12345', 1, 2 ) as unsigned integer)