how to convert date into month number?

后端 未结 7 1768
闹比i
闹比i 2021-01-19 14:40

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 
         


        
7条回答
  •  情话喂你
    2021-01-19 14:50

    Totally agree regarding writing a case when Oracle offers built-in functionality:

    SELECT EXTRACT(MONTH FROM DATE '2012-03-15') FROM DUAL;
    
    SELECT EXTRACT(MONTH FROM TO_DATE('01-JAN-12', 'DD-MON-RR')) month_to_number FROM DUAL;
    
    select to_number(to_char(to_date('01-JAN-12','dd-mon-yy'),'mm')) month_to_number from     dual;
    
    select to_number(to_char(trunc(sysdate), 'mm')) month_to_number from dual;
    

提交回复
热议问题