Oracle月份?
oracle獲得上個月的月份:select to_char(add_months(trunc(sysdate),-1),'yyyymm') from dual;oracle獲得下個月的月份:select to_char(add_months(trunc(sysdate),1),'yyyymm') from dual;oracle獲得上個月的第一天日期:select data_dt ,ADD_MONTHS(TRUNC( to_date(data_dt, 'YYYY-MM-DD'),'MM' ),-1) from a_web_visit_origin;oracle獲得上個月的第一天日期(符合當地的日期格式):select data_dt ,TO_CHAR (ADD_MONTHS(TRUNC( to_date(data_dt, 'YYYY-MM-DD'),'MM' ),-1),'YYYY-MM-DD') from a_web_visit_origin;oracle獲得上個月當天日期:select data_dt ,TO_CHAR (ADD_MONTHS(TRUNC( to_date(data_dt, 'YYYY-MM-DD') ),-1),'YYYY-MM-DD') from a_web_visit_origin;select data_dt ,ADD_MONTHS(TRUNC( to_date(data_dt, 'YYYY-MM-DD'),'MM' ),-1) from a_web_visit_origin;oracle獲得上個月的第一天日期(符合當地的日期格式):select data_dt ,TO_CHAR (ADD_MONTHS(TRUNC( to_date(data_dt, 'YYYY-MM-DD'),'MM' ),-1),'YYYY-MM-DD') from a_web_visit_origin;oracle獲得上個月當天日期:select data_dt ,TO_CHAR (ADD_MONTHS(TRUNC( to_date(data_dt, 'YYYY-MM-DD') ),-1),'YYYY-MM-DD') from a_web_visit_origin;擴展資料:日期和字符轉換函數用法(to_date,to_char):日期轉化為字符串:select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as nowTime from dual;獲取時間的年: select to_char(sysdate,'yyyy') as nowYear from dual; 獲取時間的月: select to_char(sysdate,'mm') as nowMonth from dual;獲取時間的日:select to_char(sysdate,'dd') as nowDay from dual;獲取時間的時:select to_char(sysdate,'hh24') as nowHour from dual;獲取時間的分:select to_char(sysdate,'mi') as nowMinute from dual; 獲取時間的秒:select to_char(sysdate,'ss') as nowSecond from dual;