用SQL語句獲取常見的幾種日期數值spa
---上週 SELECT TO_CHAR(TRUNC(SYSDATE, 'IW') - 7, 'yyyymmdd') FROM DUAL SELECT TO_CHAR(TRUNC(SYSDATE, 'IW') - 1, 'yyyymmdd') FROM DUAL ---本週 SELECT TO_CHAR(TRUNC(SYSDATE, 'IW') , 'yyyymmdd') FROM DUAL SELECT TO_CHAR(TRUNC(SYSDATE, 'IW') + 6, 'yyyymmdd') FROM DUAL ---上一月的第一天和最後一天 select trunc(add_months(sysdate, -1), 'mm') first_day, last_day(add_months(sysdate, -1)) last_day from dual ---本月的最後一天 SELECT TO_CHAR(last_day(add_months(sysdate, 0)), 'yyyymmdd') FROM DUAL ---當年 第一天 SELECT TO_CHAR(trunc(sysdate, 'yyyy'), 'yyyymmdd') FROM DUAL ---上年最後一天 SELECT TO_CHAR(trunc(sysdate,'iyyy'), 'yyyymmdd') FROM DUAL ---當月第一天 SELECT TO_CHAR(trunc(sysdate,'mm'), 'yyyymmdd') FROM DUAL ---當月數值 SELECT TO_CHAR(sysdate,'mm') FROM DUAL ---當週數值 SELECT TO_CHAR(sysdate,'ww') FROM DUAL