Year : 2011
Month: Nov
Day: Sun
WeekNumber(Monthwise): 4
慾望輸出:
Date
--------
2011-11-20
我怎麼能在一個單獨的SQL語句這樣做呢?
感謝
Year : 2011
Month: Nov
Day: Sun
WeekNumber(Monthwise): 4
慾望輸出:
Date
--------
2011-11-20
我怎麼能在一個單獨的SQL語句這樣做呢?
感謝
我可能會看使用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
嘗試:
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;
這可能工作。
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
這是給錯誤ORA-01843:不是有效的月份 – user1025901
工作對我來說,錯誤可能是因爲我沒有指定日期格式,已經更新。 –
+1,請參閱:http://www.techonthenet.com/oracle/functions/next_day.php – Johan