oracle中 我给出一个周数 用什么函数可以取出这周的开始日期和结束日期?

比如第32周我想知道32周的这周的开始时间和结束时间。... 比如 第32周 我想知道32周的 这周的开始时间和结束时间。 展开
 我来答
badkano
2010-11-18 · 知道合伙人体育行家
badkano
知道合伙人体育行家
采纳数:144776 获赞数:885365
团长

向TA提问 私信TA
展开全部
select SUNDAY,SATURDAY from
(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
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
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) a
where the_week=32
匿名用户
推荐于2017-08-23
展开全部
oracle中 我给出一个周数 用什么函数可以取出这周的开始日期和结束日期?
下面是代码:
CREATE OR REPLACE FUNCTION calcDates(START_DATE IN DATE, END_DATE IN DATE)
RETURN number IS
No_of_DAYS number;
BEGIN

IF START_DATE < END_DATE THEN
SELECT count(1) days
INTO NO_OF_DAYS
FROM (SELECT DISTINCT trunc(START_DATE) + level - 1 dayList
FROM dual
connect BY trunc(START_DATE) + level - 1 < = trunc(END_DATE)) A
where not exists (select 1
from dp_tbl_public_holiday b
where to_date(b.ph_date, 'YYYYMMDD') = A.dayList)
and to_char(dayList, 'D') not in (1, 7);
ELSE
SELECT 0 - count(1) days
INTO NO_OF_DAYS
FROM (SELECT DISTINCT trunc(END_DATE) + level - 1 dayList
FROM dual
connect BY trunc(END_DATE) + level - 1 < = trunc(START_DATE)) A
where not exists (select 1
from dp_tbl_public_holiday b
where to_date(b.ph_date, 'YYYYMMDD') = A.dayList)
and to_char(dayList, 'D') not in (1, 7);
END IF;

Return No_of_DAYS;
END;
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
spiderrobot
2010-11-18 · TA获得超过871个赞
知道小有建树答主
回答量:930
采纳率:0%
帮助的人:572万
展开全部
SQL> select trunc(a)-6 begin_day,trunc(a) end_day from (
2 SELECT b.a,rownum rn
3 FROM (SELECT trunc(SYSDATE,'yyyy')+ROWNUM a
4 FROM dba_objects where rownum<=366) b
5 WHERE to_char(b.a,'day')='星期六')
6 where rn=32 ;

BEGIN_DAY END_DAY
-------------- --------------
01-8月 -10 07-8月 -10

SQL> alter session set nls_date_format='yyyy-mm-dd' ;

会话已更改。

SQL> select trunc(a)-6 begin_day,trunc(a) end_day from (
2 SELECT b.a,rownum rn
3 FROM (SELECT trunc(SYSDATE,'yyyy')+ROWNUM a
4 FROM dba_objects where rownum<=366) b
5 WHERE to_char(b.a,'day')='星期六')
6 where rn=32 ;

BEGIN_DAY END_DAY
---------- ----------
2010-08-01 2010-08-07
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式