Oracle的日期比較以及處理

2022-08-13 02:45:11 字數 2279 閱讀 9154

1、日期比較時精確到日,可以使用 trunc(sysdate,'dd')函式。

函式支援格式有:yyyy mm  dd  hh mi

可以用 select trunc(sysdate,'yyyy') from dual  測試看看

【返回】:日期 select sysdate from dual --當時日期

select trunc(sysdate) from dual

select trunc(sysdate ,'dd') from dual --今天日期

select trunc(sysdate,'d')+7 from dual --本週星期日

select trunc(sysdate,'dy')+7 from dual  --本週星期日

select trunc(sysdate,'day')+7 from dual --本週星期日

select trunc(sysdate,'q') from dual--本季開始日期

select trunc(sysdate,'month') from dual --本月開始日期

select trunc(sysdate ,'mm') from dual --本月開始日期

select trunc(sysdate,'year') from dual  --本年開始日期

select trunc(sysdate ,'yyyy') from dual --本年開始日期

select trunc(sysdate ,'hh24') from dual --本小時開始時間

select trunc(sysdate ,'mi') from dual --本分鐘開始時間

select trunc(sysdate ,'cc') from dual --本世紀開始時間

select trunc(last_day(sysdate),'dd') from dual --本月最後一天

2.日期的加減

sysdate+1 加一天

sysdate+1/24 加1小時

sysdate+1/(24*60) 加1分鐘

sysdate+1/(24*60*60) 加1秒鐘

加法

select sysdate,add_months(sysdate,12) from dual;        --加1年

select sysdate,add_months(sysdate,1) from dual;        --加1月

select sysdate,to_char(sysdate+7,'yyyy-mm-dd hh24:mi:ss') from dual;  --加1星期

select sysdate,to_char(sysdate+1,'yyyy-mm-dd hh24:mi:ss') from dual;  --加1天

select sysdate,to_char(sysdate+1/24,'yyyy-mm-dd hh24:mi:ss') from dual;  --加1小時

select sysdate,to_char(sysdate+1/24/60,'yyyy-mm-dd hh24:mi:ss') from dual;  --加1分鐘

select sysdate,to_char(sysdate+1/24/60/60,'yyyy-mm-dd hh24:mi:ss') from dual;  --加1秒

減法

select sysdate,add_months(sysdate,-12) from dual;        --減1年

select sysdate,add_months(sysdate,-1) from dual;        --減1月

select sysdate,to_char(sysdate-7,'yyyy-mm-dd hh24:mi:ss') from dual;  --減1星期

select sysdate,to_char(sysdate-1,'yyyy-mm-dd hh24:mi:ss') from dual;  --減1天

select sysdate,to_char(sysdate-1/24,'yyyy-mm-dd hh24:mi:ss') from dual;  --減1小時

select sysdate,to_char(sysdate-1/24/60,'yyyy-mm-dd hh24:mi:ss') from dual;  --減1分鐘

select sysdate,to_char(sysdate-1/24/60/60,'yyyy-mm-dd hh24:mi:ss') from dual;  --減1秒

Oracle日期比較

系統時間就是發部落格的時間,即2012 8 5。1 日期比較 select from dual where sysdate to date 2000.8.5 yyyy.mm.dd select from dual where to date 2012.8.5 yyyy.mm.dd to date 2...

oracle 日期處理

當月資料 sql select from tablet wheret.create time trunc sysdate,mm and t.create time last day sysdate select from table t where t.create time trunc sysda...

oracle日期時間比較

select cicai as merchantname,tre.bank code as bankcode,sum tr.trade sum as totalmount,count as count,tr.biz type as biztype from trade relation tre,tr...