我有
Year : 2011
Month: Nov
Day: Sun
WeekNumber(Monthwise): 4
欲望输出:
Date
--------
2011-11-20
如何在单个SQL语句中执行此操作?
由于
答案 0 :(得分: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
答案 1 :(得分:1)
这可能有用。
SELECT NEXT_DAY( TO_DATE(TO_CHAR((4-1)*7) || '-' || 'NOV' || '-' || '2011','dd-mon-yyyy') ,'Sun')
FROM DUAL
请参阅:http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions093.htm
答案 2 :(得分: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;