Zolt
Zolt

Reputation: 2811

Determine the month (written) from a number in oracle

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.

Upvotes: 1

Views: 565

Answers (1)

Justin Cave
Justin Cave

Reputation: 231781

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

Upvotes: 2

Related Questions