简体   繁体   中英

Oracle - Count with letters instead of numbers

I want to convert count to Letter in Oracle.Currently I am using below query.

SELECT DECODE ((SELECT COUNT(*)FROM MyTable), 0, 'A',
                                                      1, 'B',
                                                      2, 'C',
                                                      3, 'D',
                                                      4, 'E',
                                                      5, 'F',
                                                      6, 'G',
                                                      7, 'H') 
FROM DUAL;

Is there any particular oracle function which converts digit to letter.

My syntax may be wrong, but the CHR function is what you're after...

SELECT CHR(65 + COUNT(*)) FROM MyTable

...assuming you are using a character set in which "A" has a code of 65 and the letters are sequential after that.

你可以使用CHR(48 + d),其中d是数字0,1,2等

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM