Ask the Expert

Displaying time with milliseconds in 8i

I am using the Oracle8i database. In one of my applications, I need to display time including milliseconds. The current format is "Hour:Minutes;Seconds". Required Format is "Hours:Minutes:Seconds:Milliseconds". Can you help in this issue?

    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).

NAMED "MyTimestamp"
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 ;

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 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

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: