Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert month number to full month name in oracle?

Tags:

sql

oracle

I have a month column in my table. The month numbers are stored in this month column like 1 for january, 2 for feb and so on.

How do I convert the numbers into month names such as january, february, march etc.

like image 602
ashishjmeshram Avatar asked Jul 09 '12 08:07

ashishjmeshram


People also ask

How do you convert month number to month name?

Please do as follows: Select a blank cell next to the sales table, type the formula =TEXT(A2*29,"mmm") (Note: A2 is the first number of the Month list you will convert to month name), and then drag the AutoFill Handle down to other cells. Now you will see the numbers (from 1 to 12) are converted to normal month names.

How do I get month name from month number in SQL?

To convert month number to month name we have to use a function MONTHNAME(), this function takes date column or a date as a string and returns the Month name corresponding to the month number.

How do I get the month from a date in SQL Developer?

select to_char(SYSDATE,'Month') from dual; It gives unformatted month name, with spaces, for e.g. May would be given as 'May '.

What is To_char and TO_DATE in Oracle?

To_char formats a DATE into a string using the given format mask. To_date converts a STRING into a date using the format mask. Your client then displays that date using a format mask (set at session/instance level).


1 Answers

SELECT TO_CHAR(TO_DATE(7, 'MM'), 'MONTH') AS monthname FROM DUAL;

outputs

monthname
---------
JULY

If you really want the month names in lower case or capitalised, you can also use:

TO_CHAR(TO_DATE(7, 'MM'), 'month')
TO_CHAR(TO_DATE(7, 'MM'), 'Month')
like image 54
Andriy M Avatar answered Oct 06 '22 05:10

Andriy M