Consulta con fecha
Hola!!
Yo realizo las siguientes consultas desde el código (en java):
select nombre_rotulo from centros where id_centro in(select id_centro_visitado from visitas)order by nombre_rotulo
select fecha_visita from visitas where id_centro_visitado in (select id_centro from centros where nombre_rotulo='Corte Inglés')
select nombre_apellidos from agentes where id_agente in (select id_agente from visitas where id_centro_visitado=(select id_centro from centros where nombre_rotulo='Corte Inglés') and fecha_visita='2005-03-01 17:51:32.0')
La primera consulta me devuelve el nombre del centro que es Corte Inglés.-No hay problema
La segunda me devuelve la fecha visitada que es
2005-03-01 17:51:32.0.- Un poco rara la fecha
Y la tercera me devuelve un error:
java.sql.SQLException: ORA-01861: literal does not match format string
Probé quitarle el .0 del final pero siguió saliendome el mismo error.
Hice en Sql*Plus una consulta de la fecha visitada de la tabla visitas y me devolvió un formato distinto:
01/03/05
Cambié desde el código el formato de la fecha que me devolvÃa a este:
select nombre_apellidos from agentes where id_agente in (select id_agente from visitas where id_centro_visitado=(select id_centro from centros where nombre_rotulo='Corte Inglés') and fecha_visita='01/03/05')
Pero ahora me daba otro error:
java.sql.SQLException: ORA-01843: not a valid month
Puede alguien ayudarme?
Gracias
Yo realizo las siguientes consultas desde el código (en java):
select nombre_rotulo from centros where id_centro in(select id_centro_visitado from visitas)order by nombre_rotulo
select fecha_visita from visitas where id_centro_visitado in (select id_centro from centros where nombre_rotulo='Corte Inglés')
select nombre_apellidos from agentes where id_agente in (select id_agente from visitas where id_centro_visitado=(select id_centro from centros where nombre_rotulo='Corte Inglés') and fecha_visita='2005-03-01 17:51:32.0')
La primera consulta me devuelve el nombre del centro que es Corte Inglés.-No hay problema
La segunda me devuelve la fecha visitada que es
2005-03-01 17:51:32.0.- Un poco rara la fecha
Y la tercera me devuelve un error:
java.sql.SQLException: ORA-01861: literal does not match format string
Probé quitarle el .0 del final pero siguió saliendome el mismo error.
Hice en Sql*Plus una consulta de la fecha visitada de la tabla visitas y me devolvió un formato distinto:
01/03/05
Cambié desde el código el formato de la fecha que me devolvÃa a este:
select nombre_apellidos from agentes where id_agente in (select id_agente from visitas where id_centro_visitado=(select id_centro from centros where nombre_rotulo='Corte Inglés') and fecha_visita='01/03/05')
Pero ahora me daba otro error:
java.sql.SQLException: ORA-01843: not a valid month
Puede alguien ayudarme?
Gracias
Hola.
1) alter session set NLS_DATE_FORMAT = 'DD-MM-YYYY';
2) Cuando juegues con fechas formatealas:
and fecha_visita=to_date('01-03-2005 17:51:32','dd-mm-yyyy hh24:mi:ss)
Ya nos contarás
1) alter session set NLS_DATE_FORMAT = 'DD-MM-YYYY';
2) Cuando juegues con fechas formatealas:
and fecha_visita=to_date('01-03-2005 17:51:32','dd-mm-yyyy hh24:mi:ss)
Ya nos contarás
Me sigue dando el error del principio:
select nombre_apellidos from agentes where id_agente in (select id_agente from visitas where id_centro_visitado=(select id_centro from centros where nombre_rotulo='Corte Inglés') and fecha_visita=to_date('2005-03-01 17:51:32','dd-mm-yyyy hh24:mi:ss'))
java.sql.SQLException: ORA-01861: literal does not match format string
Aún cambiando a :
alter session set NLS_DATE_FORMAT = 'DD-MM-YYYY hh24:mi:ss';
select nombre_apellidos from agentes where id_agente in (select id_agente from visitas where id_centro_visitado=(select id_centro from centros where nombre_rotulo='Corte Inglés') and fecha_visita=to_date('2005-03-01 17:51:32','dd-mm-yyyy hh24:mi:ss'))
java.sql.SQLException: ORA-01861: literal does not match format string
Aún cambiando a :
alter session set NLS_DATE_FORMAT = 'DD-MM-YYYY hh24:mi:ss';
Asumo que FECHA_VISITA es un campo tipo date.
Si es correcto, esto te deberÃa funcionar :
fecha_visita=to_date(01-03-2005 17:51:32','dd-mm-yyyy hh24:mi:ss')
Si no es un date deberÃas poner :
To_date(fecha_visita,'dd-mm-yyyy hh24:mi:ss) = to_date...................
Si es correcto, esto te deberÃa funcionar :
fecha_visita=to_date(01-03-2005 17:51:32','dd-mm-yyyy hh24:mi:ss')
Si no es un date deberÃas poner :
To_date(fecha_visita,'dd-mm-yyyy hh24:mi:ss) = to_date...................
