Kannan_SJD
Kannan_SJD

Reputation: 1072

Return character instead of integer

Is there any way in MySQL to return a character when I give integer as input?

For example

Value     Returns
-----------------
1         A
2         B
3         C
4         D

Upvotes: 0

Views: 110

Answers (2)

sshow
sshow

Reputation: 9104

You could use SELECT char(int), but please note it will only work for 27 characters, before returning [ \ ] ^ since it's using the character codes from the ASCII table

SELECT char(64 + table.column) FROM table;

Upvotes: 1

steffen
steffen

Reputation: 17048

You can use the ascii values:

select CHAR(1 + 64);
            ^ that's your 1..26

Upvotes: 0

Related Questions