1 /*开始时间(以星期一为开始时间):*/ 2 select trunc(sysdate,‘D‘)+1 from dual; 3 4 /* 结束时间(以星期日为结束时间):*/ 5 select trunc(sysdate,‘D‘)+7 from dual; 6 7 /* 月初时间:*/ 8 select trunc(sysdate,‘MM‘) from dual; 9 10 /* 月末时间:*/ 11 select last_day(sysdate) from dual; 12 13 /* 季初时间:*/ 14 select trunc(sysdate,‘Q‘) from dual; 15 16 /* 季末时间:*/ 17 select add_months(trunc(sysdate,‘Q‘),3)-1 from dual; 18 19 /*年初时间:*/ 20 select trunc(sysdate,‘yyyy‘) from dual; 21 22 /*年末时间:*/ 23 select add_months(trunc(sysdate,‘yyyy‘),12)-1 from dual; 24 25 /*一年中每月天数*/ 26 select to_char(add_months(sysdate,-level+1),‘yyyy-mm‘) month, 27 to_char(last_day(add_months(sysdate,-level+1)),‘dd‘) day from dual 28 connect by level <=12 29 order by month 30 31 /*一月中每天明细*/ 32 select to_date(‘201809‘,‘yyyymm‘)+(rownum-1) s_date from dual 33 connect by rownum<=last_day(to_date(‘201809‘,‘yyyymm‘)) - to_date(‘201809‘,‘yyyymm‘) + 1 34 order by s_date 35 36 37 /*到现在为止的12个月*/ 38 select to_char(add_months(sysdate-360, rownum - 1), ‘yyyy-mm‘) as monthlist from dual 39 connect by rownum <= months_between(trunc(sysdate,‘mm‘),trunc(sysdate-360,‘mm‘))+1 40 order by monthlist 41 42 /*月天数*/ 43 select to_char(last_day(sysdate),‘dd‘) from dual; 44 select add_months(to_date(‘201801‘, ‘yyyymm‘),1)-to_date(‘201801‘, ‘yyyymm‘) from dual;
原文:https://www.cnblogs.com/lgx5/p/14350080.html