Q

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?

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

Dig deeper on Oracle and SQL

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

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:

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close