seleccionar datos basados ​​en una columna de fecha

I was trying to select some data from my table using the following query:

select * from table1 where column1 = to_date('14-05-14','yy-mm-dd');

Where the column data type is DATE. I observed that, the above query won't return anything unless we modified it as,

select * from table1 where trunc(column1) = to_date('14-05-14','yy-mm-dd');

even though there are records available.

I checked the documentation for TRUNC.Can anyone please explain why this happens?


As per the valuable comments I think some time values may also associated with the DATE. But I cannot view/edit that time. How can I ensure there are time values associated.

enter image description here

preguntado el 28 de mayo de 14 a las 12:05

How about giving a SQL fiddle of your example!4 -

Alter your session with, ALTER SESSION SET nls_date_format = 'dd/mm/yyyy hh24:mi:ss'; and see the results. -

Ok. So the column with DATE data type by default hold the TIME value also? -

2 Respuestas

Ambos TO_DATE e TRUNC are different. See the below example.

SQL> ALTER SESSION SET nls_date_format = 'dd/mm/yyyy hh24:mi:ss';

Session altered.


28/05/2014 16:03:25


28/05/2014 00:00:00

In Your first query to_date('14-05-14','yy-mm-dd') is comparing with the date field column1 in your table which has time values also. Whereas in Your 2nd query You are truncating the time part from table data and from Your query, that's why it's matching.

contestado el 28 de mayo de 14 a las 12:05

The DATE datatype stores the year (including the century), the month, the day, the hours, the minutes, and the seconds (after midnight).

TRUNC function will truncate the date to the day value, so that any hours, minutes, or seconds will be truncated off.

For more info please look at these below links

contestado el 28 de mayo de 14 a las 12:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.