How do I cast a NUMBER value to a single CHAR in Oracle? How do I cast a NUMBER value to a single CHAR in Oracle? oracle oracle

How do I cast a NUMBER value to a single CHAR in Oracle?


As per my comment on @northpole's answer...

The closest to what you want might not be exactly correct but the CHR function would convert the numeric to it's ascii equivalent.
i.e. alpha := chr(113); would put the char "q" into the alpha variable thereby storing your numeric "113" as a single byte.


You have a couple options. You can use TO_CHAR and do something like:

TO_CHAR(rank,'99')

Or use the CAST function and fix your attempt by providing a larger CHAR:

CAST(rank as CHAR(2))

The reason for that is as Ollie described in his comment.


You could try this:

SUBSTR(CAST(rank as CHAR(2)), 2, 1)