简体   繁体   中英

Compare two dates based on timestamp on Oracle 11g

Am dealing with two tables A and B on Oracle 11g and trying to compare records ( A.TRANSACTION_TIMESTAMP and B.LAST_TRANSACTION_TIMESTAMP ) based on timestamp on columns with datatype DATE

Based on what i have tried, the below query does not give the expected output and returns records even when TRANSACTION_TIMESTAMP is less than LAST_TRANSACTION_TIMESTAMP

TO_CHAR(TRANSACTION_TIMESTAMP, 'DD-MON-YYYY HH24:MI:SS') >= 
(SELECT TO_CHAR(LAST_TRANSACTION_TIMESTAMP, 'DD-MON-YYYY  HH24:MI:SS') 
  FROM LAST_RAN_TIME)

Would highly appreciate if anyone can provide some inputs on comparing Dates with timestamp on Oracle 11g

Do not convert with TO_CHAR. Just compare columns directly.

The comparision is failing because you are using strings that start with the day!

TRANSACTION_TIMESTAMP >= (SELECT LAST_TRANSACTION_TIMESTAMP FROM LAST_RAN_TIME)

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