✔ 最佳答案
Use NEXT_DAY function, returns the first weekday from the date specified.
NEXT_DAY(date, weekday)
SELECT NEXT_DAY( TO_DATE ('11/01/2007', 'MM/DD/YYYY'), 'SUNDAY')
FROM DUAL
returns "4-Nov-2007"
SELECT (TO_DATE ('11/30/2007', 'MM/DD/YYYY')
- NEXT_DAY( TO_DATE ('11/01/2007', 'MM/DD/YYYY'), 'SUNDAY') + 1) /7
FROM DUAL
If the result is an integer, that is the answer. If the result is a decimal number, round up to the next integer.
For example, find the Sunday between 5-Nov-2007 and 24-Nov-2007. Next_Day function returns 11-Nov-2007. Between 11-Nov and 24-Nov are 14 days (24 - 11 +1). 14 / 7 = 2 Sundays
To Find the Sundays between 3-Nov-2007 and 19-Nov-2007. Next_Day function returns 4-Nov-2007. Between 4-nov and 19-Nov are 16 days (19 - 4 +1). 16 / 7 = 2.3 = 3 Sundays