I have a temp table.
It has last_update column in 2/10/2018 6:01:50 PM
datetime format.
How can I write THE BEST QUERY to display all information that's updated on 02-Oct-2018 day ?
You can use trunc
function
select *
from tab
where trunc(last_update) = date'2018-10-02'
Use trunc function for getting the same day:
trunc(last_update) = trunc(to_date('02-Oct-2018', 'DD-MONTH-YYYY'))
The TRUNC (date) function returns date with the time portion of the day truncated to the unit specified by the format model fmt. The value returned is always of datatype DATE, even if you specify a different datetime datatype for date. If you omit fmt, then date is truncated to the nearest day .
You can also use format DD-MON-YYYY
It is preferable to avoid TRUNC
especially if you have an index on the column last_update
. A simple where
condition should be better and may be better performant.
WHERE last_update >= date '2018-10-02' AND
last_update < date '2018-10-02' + 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.