I have an Oracle 10g table containing 2 date columns, DATE_VALID_FROM from and DATE_VALID_TO.
MY_TABLE:
DATE_VALID_FROM | DATE_VALID_TO | VALUE
15-FEB-13 | 17-FEB-13 | 1.833
14-FEB-13 | 14-FEB-13 | 1.836
13-FEB-13 | 13-FEB-13 | 1.824
12-FEB-13 | 12-FEB-13 | 1.82
11-FEB-13 | 11-FEB-13 | 1.822
08-FEB-13 | 10-FEB-13 | 1.826
07-FEB-13 | 07-FEB-13 | 1.814
06-FEB-13 | 06-FEB-13 | 1.806
05-FEB-13 | 05-FEB-13 | 1.804
04-FEB-13 | 04-FEB-13 | 1.796
01-FEB-13 | 03-FEB-13 | 1.801
The range on the date columns isn’t always one day (weekends).
I can retrieve the value for a single date like this,
select DATE_VALID_FROM, DATE_VALID_TO, VALUE
from MY_TABLE
where DATE_VALID_FROM <= TO_DATE('16-FEB-13', 'dd-MON-yy')
and DATE_VALID_TO >= TO_DATE('16-FEB-13', 'dd-MON-yy')
Is it possible to retrieve the values for multiple random dates in a single query?
e.g. Values for the 1st, 5th, 6th, 11th and 16th Feb.
Producing this result set:
DATE_VALID_FROM | DATE_VALID_TO | VALUE
15-FEB-13 | 17-FEB-13 | 1.833
11-FEB-13 | 11-FEB-13 | 1.822
06-FEB-13 | 06-FEB-13 | 1.806
05-FEB-13 | 05-FEB-13 | 1.804
01-FEB-13 | 03-FEB-13 | 1.801
Try:
SQLFiddle here