how to convert date into month number?

2019-02-27 15:38发布

I have a column Month in my table. The month name and date are stored in this month column like

Month    
01-JAN-12 
02-FEB-12 

and so on.

How do I convert the DATE into month number such as

Month
1 
2 

etc.

7条回答
聊天终结者
2楼-- · 2019-02-27 16:09

Use TO_CHAR function as in TO_CHAR(my_column, 'MM').

For your specific format you would need the format converter TO_CHAR(month, 'FmMM') (thanks to Nicholas Krasnov for this trick).

If your month column is not already of a date type you will first need to convert it to a date: TO_CHAR(TO_DATE(month, 'DD-Mon-IY'), 'FmMM').

查看更多
登录 后发表回答