2011-11-03 71 views

回答

4

我可能會看使用NEXT_DAY函數返回給定的日期之後發生提供平日的第一天。一旦你有了,你可以添加所需的週數。

這方面的一個例子是:

with test_data as (
    select 
    '2011' as the_year, 
    'Nov' as the_month, 
    'Sun' as the_day, 
    4 as the_week 
    from dual 
) 
select 
    the_year, the_month, the_day, the_week, 
    next_day(to_date(the_year||the_month, 'YYYYMON') - 1, the_day) + 
    7* (the_week -1) as the_date 
from test_data 
+0

+1,請參閱:http://www.techonthenet.com/oracle/functions/next_day.php – Johan

0

嘗試:

SELECT A.B + B.D YourDate 
FROM (SELECT TO_DATE (Your4DigitYear || LPAD (YourMonth, 2, '0') || LPAD (DECODE (YourWeekOfMonth, 1, '1', (YourWeekOfMonth - 1) * 7), 2, '0'), 'YYYYMMDD') B FROM DUAL) A, (SELECT LEVEL - 1 D FROM DUAL CONNECT BY LEVEL < 15) B WHERE 
TO_CHAR (A.B + B.D, 'D') = YourDayOfWeek AND 
TO_CHAR (A.B + B.D, 'W') = YourWeekOfMonth; 
相關問題