I have table test1 and have one column DOJ with timestamp datatype having few records as shown below. Here i need the difference im milliseconds between doj and systimestamp.
SELECT DOJ FROM TEST1;
DOJ
----------------------------
21-MAR-14 09.25.34.514526000
21-MAR-14 09.25.34.520345000
22-MAR-14 09.25.34.523144000
22-MAR-14 09.25.34.527770000
23-MAR-14 09.25.34.532482000
23-MAR-14 09.25.34.535603000
24-MAR-14 09.25.34.538556000
24-MAR-14 09.25.34.541729000
SELECT SYSTIMESTAMP FROM DUAL;
SYSTIMESTAMP
--------------
24-MAR-14 09.48.10.251556000 +00:00
Can some one please help me with this.
If you need to handle leap seconds then you can create a utility package that will adjust the epoch time to account for this:
Then you can do:
And get the output:
Note: you will need to keep the package up-to-date when new leap-seconds are proposed.
Expanding René's answer a bit, if you want the total milliseconds then you need to extract and combine all of the elements from the interval that's produced by subtracting one timestamp from another:
SQL Fiddle, including the Unix epoch date for comparison, though you'd need to adjust that for your server time zone.