首页 > 解决方案 > Mysql数据库将整数添加到ascii

问题描述

在此处输入图像描述

大家好,所以我想将一个字符串转换为ascii代码,我不得不将它拆分为char并将每个char转换为ascii,然后在最后合并它们。我想在将它们重新合并在一起之前为每个 ascii 字符添加一些常量值。有人可以帮助我该怎么做吗?任何帮助将不胜感激。谢谢

标签: mysqlsqldatabasestringrecursive-query

解决方案


只需在 内进行计算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

推荐阅读