Reputation: 7253
We have a Java Web application deployed in SAP Netweaver that accesses an Oracle 10g Database through plain JDBC. The application was working fine until a few days ago, when a query was causing the following error:
ORA-01843: not a valid month
The query that's giving us trouble is this:
SELECT *
FROM (SELECT *
FROM (SELECT inspeccion.sociedad_id,
inspeccion_id,
estado_id,
(SELECT des_estado
FROM estado
WHERE estado.estado_id = inspeccion.estado_id)
des_estado,
(SELECT numero_secuencia
FROM estado
WHERE estado.estado_id = inspeccion.estado_id)
numero_secuencia,
planta_id,
(SELECT des_planta
FROM planta
WHERE planta.planta_id = inspeccion.planta_id)
des_planta,
area_id,
(SELECT des_area
FROM area
WHERE area.area_id = inspeccion.area_id) des_area
,
igp_id,
'-'
nom_lider,
nom_inspector,
nom_responsable,
To_char(fecha_inspeccion, 'DD/MM/YYYY')
fecha_inspeccion,
observacion,
recomendacion
FROM inspeccion) inspeccion) t_inspeccion
WHERE estado_id NOT IN ( 10 )
AND t_inspeccion.estado_id IN ( 11, 12 )
AND t_inspeccion.planta_id = 42
AND t_inspeccion.fecha_inspeccion >= To_date('01/11/2010', 'dd/mm/yyyy')
AND t_inspeccion.sociedad_id = '0101'
ORDER BY t_inspeccion.numero_secuencia,
t_inspeccion.fecha_inspeccion
We were suspecting of the To_date('01/11/2010', 'dd/mm/yyyy')
statement, but when we run the query trough DBVisualizer we have no trouble at all.
I'm kind of lost here. Maybe there's a DB Setting that's messing with the query, or some SAP Netweaver configuration? Or perhaps some Oracle Driver issue?
Upvotes: 0
Views: 12243
Reputation: 191275
In the nested select that becomes t_inspeccion
you have:
To_char(fecha_inspeccion, 'DD/MM/YYYY') fecha_inspeccion,
... and then in the outer where
clause you have:
AND t_inspeccion.fecha_inspeccion >= To_date('01/11/2010', 'dd/mm/yyyy')
Assuming the original inspection.fecha_inspeccion
is a date
, you seem to be converting to to a string, then doing an implicit conversion back to a date to compare it to your fixed value. I suspect the implicit conversion of t_inspeccion.fecha_inspeccion
is throwing the error, possibly from an unexpected NLS_DATE_FORMAT
setting; which in Java is normally obtained from your locale. From the error I'd guess it's implicitly using MM/DD/YYYY, but could easily be something else.
I don't see why you had the to_char()
at all though, unless you particularly want the text format in the results; in which case you need to either explicitly convert the date back in the where
clause:
AND To_date(t_inspeccion.fecha_inspeccion, 'dd/mm/yyyy')
>= To_date('01/11/2010', 'dd/mm/yyyy')
... or pull the original date column as well and compare using that; though that would perhaps need you to list all the other columns in the outermost select
. If you are, or expect to be, using an index on fecha_inspeccion
then you may also be degrading performance by treating it as a string.
Upvotes: 5