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;
2024-07-24 广告