Wednesday, September 30, 2009

Oracle: Current datetime with milliseconds.

Nothing is easy with oracle for a starter. What doesn’t work:

SELECT TO_CHAR(sysdate, 'HH24:MI:SS.FF4') from dual;

It gives the “ORA-01821 - date format is not recognized”. Explanation is that sysdate in oracle is given with precision of a second.

What does work:

SELECT TO_CHAR(SYSTIMESTAMP, 'HH24:MI:SS.FF4') from dual;

returns: 13:07:13.4239

Similar post:

http://jasonvogel.blogspot.com/2006/11/example-using-systimestamp-milliseconds.html

See if oracle docs say anything about it (guess…): http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions172.htm

No comments: