Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
OK guys, first of all, I have checked many websites about this error and, unfortunately, none of them helped me. I have the simple following query:
select * from (
select to_date(cal.year || cal.month || cal.day, 'yyyymmdd') as datew,
cal.daytype as type
from vw_calendar cal)
where datew > sysdate;
When I try to execute the entire query, this error shows up:
ORA-01839: date not valid for month specified
If I execute only the query:
select to_date(cal.year || cal.month || cal.day, 'yyyymmdd') as datew,
cal.daytype as type
from vw_calendar cal;
It worked absolutely fine. If you want to view the results of the query: http://pastebin.com/PV95g3ac
I checked the days of the month like day 31 or leap year and everything seems correct. I don't know what to do anymore. My database is a Oracle 10g and I tried to execute the query on SQL Developer and PL/SQL Developer. Same error on both IDE.
–
–
–
–
Actually the issue is some months have 30 days and some have 31, so the query which you are forming, it is trying to get 31st day of that month which is invalid and hence the error. For Example:
it may be trying for date like: 31-NOV-2016 which is not correct, NOV has only 30 days.
Well, I found a workaround, not a solution. If anyone knows the "correct" solution for this problem, I appreciate if you share with us. My "solution" convert the date to number and then compare with a sysdate
(converted too). Take a look:
select * from
( select to_number(cal.year||cal.month||cal.day) as datew,
cal.daytype as type from vw_calendar cal ) a
where a.datew > to_number(to_char(sysdate, 'yyyymmdd'));
Thanks to everyone!
select * from (
select to_date(cal.year || cal.month || cal.day, 'yyyymmdd') as datew,
cal.daytype as type
from vw_calendar cal) a
where a.datew > sysdate;
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.