Question

I have the following values in one column of a table: 1, 2, 3, 4, 5 ... 12 for the months of the year. These are just numbers, not dates, or derived from dates, or anything like that.

How do I get the month (written out) from these numbers? So if I do

SELECT TO_NUMBER(TO_CHAR(TO_DATE('December', 'Month'), 'MM')) MONTH_NUM FROM DUAL;

I can get the number from the month. But how do I get the month from the number (the opposite)? If the value was 1, the output should be Jan. If the value was 2, the output should be Feb. And so on.

Was it helpful?

Solution

to_char( to_date( <<the number>>, 
                  'MM' ),
         'fmMonth' )

should give you what you're looking for.

  1* select to_char( to_date( 1, 'MM' ), 'fmMonth' ) from dual
SQL> /

TO_CHAR(TO_DATE(1,'MM'),'FMMONTH')
------------------------------------
January
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top