我有一个存储十六进制的char(32)列。我需要将这个十六进制数转换为十进制,比如decimal(40,0),因为一个无符号的bigint不足以容纳这个32个字符的十六进制。我找不到一种方法来做这个约定,十六进制到十进制。
任何人请提前帮助和感谢你!数据库
对不起,这是在Sybase ase 15中
发布于 2013-12-25 07:17:00
这不是最优雅的解决方案-最好使用循环而不是重复的代码行-或者甚至只使用4字符子字符串的块来减少行数,而不是一次使用一个字符
此外,此解决方案还假设十六进制字符串已完全填充(如果它们是空白填充的,则必须执行一些额外的操作来解析字符串并将字节放入正确的存储桶中)
但从根本上说,这就是我们的想法:
create variable h varchar(32);
set h = 'FEDCBA9876543210FEDCBA9876543210';
create variable a decimal(40,0);
set a =
hextoint(substr(h,1,1))*power(16,31)+
hextoint(substr(h,2,1))*power(16,30)+
hextoint(substr(h,3,1))*power(16,29)+
hextoint(substr(h,4,1))*power(16,28)+
hextoint(substr(h,5,1))*power(16,27)+
hextoint(substr(h,6,1))*power(16,26)+
hextoint(substr(h,7,1))*power(16,25)+
hextoint(substr(h,8,1))*power(16,24)+
hextoint(substr(h,9,1))*power(16,23)+
hextoint(substr(h,10,1))*power(16,22)+
hextoint(substr(h,11,1))*power(16,21)+
hextoint(substr(h,12,1))*power(16,20)+
hextoint(substr(h,13,1))*power(16,19)+
hextoint(substr(h,14,1))*power(16,18)+
hextoint(substr(h,15,1))*power(16,17)+
hextoint(substr(h,16,1))*power(16,16)+
hextoint(substr(h,17,1))*power(16,15)+
hextoint(substr(h,18,1))*power(16,14)+
hextoint(substr(h,19,1))*power(16,13)+
hextoint(substr(h,20,1))*power(16,12)+
hextoint(substr(h,21,1))*power(16,11)+
hextoint(substr(h,22,1))*power(16,10)+
hextoint(substr(h,23,1))*power(16,9)+
hextoint(substr(h,24,1))*power(16,8)+
hextoint(substr(h,25,1))*power(16,7)+
hextoint(substr(h,26,1))*power(16,6)+
hextoint(substr(h,27,1))*power(16,5)+
hextoint(substr(h,28,1))*power(16,4)+
hextoint(substr(h,29,1))*power(16,3)+
hextoint(substr(h,30,1))*power(16,2)+
hextoint(substr(h,31,1))*power(16,1)+
hextoint(substr(h,32,1))*power(16,0);https://stackoverflow.com/questions/20721435
复制相似问题