通过给出年份来获取所有周的开始日期和结束日期

时间:2013-12-12 06:32:20

标签: oracle10g

我有一个查询,显示一组52个数字以及该周的相应日期

         SELECT kkk, TO_CHAR (start_date, 'DD-MON-YYYY'),
              TO_CHAR (start_date + 6, 'DD-MON-YYYY') AS end_day
            FROM (SELECT       TRUNC (TRUNC (TO_DATE ('2014', 'YYYY'), 'YYYY') + 1 * 7,
                        'IW'
                       )
               - 1 start_date,
               ROWNUM AS kkk
          FROM DUAL
    CONNECT BY ROWNUM <= 52);

但是这个问题的问题在于我只获得了第一周的日期而不是连续几周的日期。请帮助

1 个答案:

答案 0 :(得分:0)

试试这个,

SELECT kkk,
       TO_CHAR(start_date, 'DD-MON-YYYY') start_date, 
       TO_CHAR(start_date + 6, 'DD-MON-YYYY') end_day
FROM(
     SELECT TRUNC(Trunc(to_date('2014', 'YYYY'),'YYYY')+ LEVEL * 7,'IW')-1 start_date , 
            ROWNUM kkk
     FROM duaL
     CONNECT BY LEVEL <= 52
     );

您可以使用ROWNUM,Like,

代替LEVEL
 SELECT TRUNC(Trunc(to_date('2014', 'YYYY'),'YYYY')+ LEVEL * 7,'IW')-1 start_date , 
        level kkk
 FROM duaL
 CONNECT BY LEVEL <= 52