简体   繁体   中英

Oracle SQL Date Time Inquiry

So I have an oracle sql table that has information that looks like below:

USERID        DATETIME_STAMP               DESCR254   
=================================================================     
ZX08067       6/22/2012 4:26:03.589868 PM  Tools and Calculators
-------
-------

How would I retrieve the row shown by getting the exact DATETIME_STAMP? I tried the below query, but it doesn't return any rows. What's wrong with the DATETIME_STAMP part?

select * from sysadm.PS_IS_STATS_URLS
where USERID = 'ZX08067'
AND DESCR254 = 'Tools and Calculators'
and DATETIME_STAMP = (to_timestamp('22/06/2012 04:26.03.589868', 'dd/mm/yyyy hh24:mi.ss.ff'))

Your database is clearly showing the time in 12-hour format with a "PM" suffix. Your query is using 24-hour time, so it's off by 12 hours. The query should be:

select * from sysadm.PS_IS_STATS_URLS
where USERID = 'ZX08067'
AND DESCR254 = 'Tools and Calculators'
and DATETIME_STAMP = (to_timestamp('22/06/2012 16:26.03.589868', 'dd/mm/yyyy hh24:mi.ss.ff'))

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM