Requires Free Membership to View
Until you get to 9i, you cannot directly use milliseconds because Oracle only stores times in HH:MI:SS format. In 9i, this capability is now available. But since you're on 8i, try using this Java procedure (you must have Java capability installed for your 8i database before this will work).
CREATE OR REPLACE JAVA SOURCE
NAMED "MyTimestamp"
AS
import java.lang.string;
import java.sql.timestamp;
public class MyTimestamp
{ public static String getTimestamp()
{
return (new Timestamp(System.currentTimeMillis())).toString();
}
};
/
create or replace function my_timestamp return varchar2
as language java
name 'MyTimestamp.getTimestamp() return java.lang.String';
/
To use:
select my_timestamp from dual ;
MY_TIMESTAMP
-----------------------
2002-04-18 16:54:38.688
This example is courtesy of Tom Kyte's book Expert One-on-One Oracle. I'd
recommed the book for more info and other cool stuff.
For More Information
- What do you think about this answer? E-mail the editors at editor@searchDatabase.com with your feedback.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
This was first published in April 2002

Join the conversationComment
Share
Comments
Results
Contribute to the conversation