標籤:oracle font trunc logs 格式 處理 sys 否則 說明符
select to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘) from dual; --顯示目前時間2017 - 04 - 24 18 :42 :17select trunc(sysdate, ‘year‘) from dual; --截取到年(本年的第一天)2017 / 1 / 1select trunc(sysdate, ‘q‘) from dual; --截取到季度(本季度的第一天)2017 / 4 / 1select trunc(sysdate, ‘month‘) from dual; --截取到月(本月的第一天)或select trunc(sysdate, ‘mm‘) from dual; --截取到月(本月的第一天)2017 / 4 / 1select trunc(sysdate, ‘‘) from dual;空select to_char(trunc(sysdate), ‘yyyymmdd hh24:mi:ss‘) from dual; --預設截取到日(當日的零點零分零秒)20170424 00 :00 :00select trunc(sysdate - 1, ‘w‘) from dual; -- 離目前時間最近的周四,若當天為周四則返回當天,否則返回上周四2017 / 4 / 22select trunc(sysdate, ‘ww‘) from dual; --截取到上周末(上周周六)2017 / 4 / 23select trunc(sysdate, ‘day‘) from dual; --截取到周(本周第一天,即上周日)2017 / 4 / 23select trunc(sysdate, ‘iw‘) from dual; --本周第2天,即本周一2017 / 4 / 24select to_char(trunc(sysdate, ‘dd‘), ‘yyyymmdd hh24:mi:ss‘) from dual; --截取到日(當日的零點零分零秒)20170424 00 :00 :00select trunc(sysdate, ‘hh24‘) from dual; --截取到小時(當前小時,零分零秒)2017 / 4 / 24 18 :00 :00select trunc(sysdate, ‘mi‘) from dual; --截取到分(當前分,零秒)2017 / 4 / 24 18 :44 :00select trunc(sysdate, ‘ss‘) from dual; --報錯,沒有精確到秒的格式報錯:有效位數規範錯誤
oracle trunc 函數處理日期格式,