Basically I have the following query that works but doesn't give the right data:
SELECT a.* FROM
( SELECT a.*, rownum rnum FROM (
SELECT
edate.expiration_date
FROM
...
( SELECT To_Date(c.Value, 'MM/DD/YYYY HH24:MI:SS') expiration_date
FROM ... ) edate
) a WHERE rownum <= 20)
a WHERE rnum >= 1 AND
expiration_date < to_date('1/29/2010', 'MM/DD/YYYY HH24:MI:SS')
The reason it doesn't work is that because the rownum/rnum evaluations are done concurrently with the date checking, it only gets rownums (for example) 1, 4, 6, 9 that have dates before 1/29/2010, instead of the first 20 dates that have a date less than 1/29/2010.
So basically the area
expiration_date < to_date('1/29/2010', 'MM/DD/YYYY HH24:MI:SS')
has to be put inside the inner SELECTs, but whenever I try to do it I get an invalid month error. How can I cast the selects or the subqueries into to_date
s so that it works?