Map sequence of numbers to corresponding letters
P粉304704653
P粉304704653 2023-08-30 16:24:23
0
2
494
<p>I have a <code>int</code> column that contains values ​​no greater than 20. I want to select its corresponding uppercase letter: </p> <pre class="brush:php;toolbar:false;">1 = A 2=B 3=C ...</pre> <p>I don't care what happens after Z because the column does not contain larger values. Is there an easy way to convert this to single byte characters using a SQL query? </p>
P粉304704653
P粉304704653

reply all(2)
P粉269847997

Another MySQL-specific alternative uses elt

select elt(col,'A','B','C','D','E','F',...);

Demo

P粉055726146

Add 64 to the integer and you get the ASCII value of the letter you want.

mysql> select CHAR(1+64);
+------------+
| CHAR(1+64) |
+------------+
| A          |
+------------+

Read https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_char

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template