I have a requirement to get records from a table that are systimestamp > LAST_UPDATE_TS + 5 minutes interval
Could you please help with query?
ORACLE DB - 11G Version.
I have tried this as below but not working as expected.
SYSTIMESTAMP : 11-MAR-20 06.06.00.070695 AM -05:00
LAST_UPDATE_TS : 11-MAR-20 06.05.50.781167 AM
After applying this condition, systimestamp > LAST_UPDATE_TS + INTERVAL '5' MINUTE,
I expect no data should return, but still i get rows that doesn't satisfy condition.
You are comparing
SYSTIMESTAMPwhich is aTIMESTAMP WITH TIME ZONEdata type to aTIMESTAMP(6)data type; this requires a conversion to a time zone.If you use:
The you can see the time zone your session is using.
On db<>fiddle, the default is UTC (+00:00) and running:
Outputs:
Since
2020-03-11 06:06:00.070695 -05:00is greater than2020-03-11 06:10:50.781167 +00:00.If you change the session time zone:
and run the same query again (a different column alias was used to prevent caching):
Then the output has zero rows:
If you want to manually set the timezone in the conversion then you can use the
FROM_TZfunction:Which, again, outputs zero rows:
db<>fiddle here