sql过程算法生成十六进制数(使用字符串)

ny6fqffe  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(258)

我正在尝试用sql(存储过程)生成一个算法,它将生成非十进制的数字系统(我们可以在这里使用十六进制),并将它们写进文件中。唯一的问题是,我只需要使用字符串就可以了。我已经声明了我的字符集:“0123456789def”,现在我需要在witch中创建一个循环,生成下一个元素并将其保存到文件中。

kx1ctssn

kx1ctssn1#

也许您正在寻找十进制->十六进制转换?

with data (n) as (
values (90)
union  all
select n + 1
from   data
where  n < 100
),
    alphabet (a) as (
values ('0123456789ABCDEF')
),
    dechex (orig,n,hx) as (
select n, n / 16,cast(substr(a,mod(n, 16) + 1, 1) as varchar(10))
from   data
cross  join alphabet
union  all
select orig,n / 16,substr(a,mod(n, 16) + 1, 1) concat hx
from   dechex
cross  join alphabet
where  n > 0
)
select orig,hx
from   dechex 
where  n = 0
order  by orig

相关问题