I have following query (BOCRTNTIME - varchar e.g 2015-02-28 12:21:45, VIEW_BASE_MARIX_T - some view
):
select BOCRTNTIME
from VIEW_BASE_MARIX_T
where to_date(substr(BOCRTNTIME,1,10),'YYYY-MM-DD')
between (to_date ('2016-01-01', 'YYYY-MM-DD'))
and (to_date ('2016-02-01', 'YYYY-MM-DD'))
On executing I get error:
ORA-01839: "date not valid for month specified"
I thought that there are can be incorrect data in BOCRTNTIME
, so execute following query:
select distinct
substr(BOCRTNTIME,1,8),
substr(BOCRTNTIME,9,2)
from VIEW_BASE_MARIX_T
order by substr(BOCRTNTIME,9,2);
But everything looks fine: http://pastebin.com/fNjP4UAu. Also following query executes without any error:
select to_date(substr(BOCRTNTIME,1,10),'YYYY-MM-DD')
from VIEW_BASE_MARIX_T;
I already tried add trunc()
to all to_date()
but no luck. Also I create pl/sql procedure that takes one by one item form VIEW_BASE_MARIX_T
and convert it to date - and everything works just fine.
Any ideas why I get error on first query?
UPD: Query on table that used in view works fine, but in view - not
UPD2: We have few enviroments with same products, but get error only on one
UPD3: Issue was resolved by search non valid dates in table that used in view