标签:
周日结束明王h1日月 |
分类: ORACLE |
oracle 第几周 开始日期 结束日期
日月明王BLOG http://blog.sina.com.cn/u/1727546625
select trunc(sysdate, 'MM')+rownum-1 as wwm from user_objects
where rownum < 拼出一年的日期。
366to_char(wwm,'D')=1 得到周日的日期,
decode(sign(sunday.the_day-saturday.the_day),-1,sunday.the_day,sunday.the_day-7)
当本周的周日大于周六的日期的时候,那么说明ORACLE对周的理解有误,所以将周日减7天得到真正的本周的第一天。
SQL> l
select
select
sunday.the_week,decode(sign(sunday.the_day-saturday.the_day),-1,sunday.the_day,sunday.the_day-7)
sunday,saturday.the_day saturday from
(select to_char(wwm,'WW') the_week,to_char(wwm,'D') the_daynum,wwm the_day from (select
(select to_char(wwm,'WW') the_week,to_char(wwm,'D') the_daynum,wwm the_day from (select
trunc(sysdate, 'MM')+rownum-1 as wwm from user_objects where
rownum < 366) where
to_char(wwm,'D')=1 ) sunday,
(select to_char(wwm,'WW') the_week,to_char(wwm,'D') the_daynum,wwm the_day from (select
(select to_char(wwm,'WW') the_week,to_char(wwm,'D') the_daynum,wwm the_day
trunc(sysdate, 'MM')+rownum-1 as wwm from user_objects where
rownum < 366) where
to_char(wwm,'D')=7 ) saturday
where sunday.the_week=saturday.the_week
SQL> /
where sunday.the_week=saturday.the_week
SQL> /
THE_
SUNDAY
SATURDAY
---- -------------- --------------
01
31-12月-06
06-1月 -07
02 07-1月
-07
13-1月 -07
03 14-1月
-07
20-1月 -07
04 21-1月
-07
27-1月 -07
05 28-1月
-07
03-2月 -07
06 04-2月
-07
10-2月 -07
07 11-2月
-07
17-2月 -07
08 18-2月
-07
24-2月 -07
09 25-2月
-07
03-3月 -07
10 04-3月
-07
10-3月 -07
11 11-3月
-07
17-3月 -07
12 18-3月
-07
24-3月 -07
13 25-3月
-07
31-3月 -07
14 01-4月
-07
07-4月 -07
15 08-4月
-07
14-4月 -07
16 15-4月
-07
21-4月 -07
17 22-4月
-07
28-4月 -07
18 29-4月
-07
05-5月 -07
19 06-5月
-07
12-5月 -07
20 13-5月
-07
19-5月 -07
21 20-5月
-07
26-5月 -07
22 27-5月
-07
02-6月 -07
23 03-6月
-07
09-6月 -07
24 10-6月
-07
16-6月 -07
25 17-6月
-07
23-6月 -07
26 24-6月
-07
30-6月 -07
27 01-7月
-07
07-7月 -07
28 08-7月
-07
14-7月 -07
29 15-7月
-07
21-7月 -07
30 22-7月
-07
28-7月 -07
31 29-7月
-07
04-8月 -07
32 05-8月
-07
11-8月 -07
33 12-8月
-07
18-8月 -07
34 19-8月
-07
25-8月 -07
35 26-8月
-07
01-9月 -07
36 02-9月
-07
08-9月 -07
37 09-9月
-07
15-9月 -07
38 16-9月
-07
22-9月 -07
39 23-9月
-07
29-9月 -07
40 30-9月
-07
---- -------------- --------------
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40