Mysql数据库在ascii中添加一个整数。

问题描述 投票:0回答:1

enter image description here

大家好,所以我想把一个字符串转换成ascii码,我必须把它拆成char,并把每个char转换成ascii,然后在最后把它们合并。我想在合并之前给每个ascii字符添加一些常量值。谁能帮帮我,我应该怎么做呢?任何帮助将是非常感激的。谢谢你的帮助

mysql sql database string recursive-query
1个回答
1
投票

只要在里面进行计算就可以了。group_concat():

set @word = 'hello';

with recursive cte as (
    select @word as word, left(@word, 1) as val, 1 as idx
    union all
    select word, substring(word, idx + 1, 1), idx + 1 
    from cte 
    where idx < char_length(word)
)
select group_concat(ascii(val) + @add order by idx separator '') ascii_word from cte
© www.soinside.com 2019 - 2024. All rights reserved.