码迷,mamicode.com
首页 > 数据库 > 详细

Oracle中取日斯的sql语句

时间:2021-02-01 11:55:16      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:char   dual   level   from   row   order   class   ora   nbsp   

 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;

 

Oracle中取日斯的sql语句

标签:char   dual   level   from   row   order   class   ora   nbsp   

原文地址:https://www.cnblogs.com/lgx5/p/14350080.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!