Modify characters of a string to their ASCII code plus 10, SQL

73 Views Asked by At

I am using mariadb 10.3 and I'm trying to create a procedure that modifies all characters of a string, to each CHAR ASCII code, 10 position ahead.

I'm having trouble to find any functions to approach this problem, thanks.

For example given the string 'man':

ASCII codes: m = 109, a = 97, n = 110

Plus 10: 119 = w, 107 = k, 120 = x

So the function should return: 'wkx'

1

There are 1 best solutions below

0
On

This works:

    DECLARE longitud smallint;  
    DECLARE nuevaCadena varchar(100);

    set longitud = LENGTH(cadena);
    set nuevaCadena = '';

        FOR i IN 1 .. longitud DO 
    
            set nuevaCadena = concat(nuevaCadena,char(ascii(substring(cadena,i)) + 10));
    
        END FOR;