Solved

How to handle milliseconds in Oracle

Posted on 1998-10-08
9
14,274 Views
Last Modified: 2012-06-27
I have a Sybase database that we are migrating to Oracle. In Sybase we can store milliseconds in a datetime field. How can I do the same in Oracle. There must be a way to do this since I would assume there is a lot of scientific data which  deals with milliseconds. Any help will be greatly appreciated.
0
Comment
Question by:jbiswas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 3

Expert Comment

by:junfeb
ID: 1081871
I don't think you can handle milliseconds in Oracle unfortunately.
There isn't a way to obtain the current time, down to the milisecond  into  a PL/SQL variable either.
Though I have seen some info about enhancement requests requesting this function to the time datatype. May be once they get that in, it would be available.
Hope this helps.
0
 
LVL 2

Author Comment

by:jbiswas
ID: 1081872
I know what you have written, and possibly that is the fact, but I was wondering how people store data for scientific applications in Oracle where milliseconds abound. There must be a way to do this!!!!!
0
 
LVL 3

Expert Comment

by:vlad_impala
ID: 1081873
You would have to store the data in a varchar2 field and convert it, or perhaps store to a second precision in a standard date field and store just the millisecond element in another number field.  The application would then have to convert/interpret the data as appropriate.

Vlad.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:junfeb
ID: 1081874
Of Course, you could store the millisecond value , by inserting it yourself into a varchar2 field. But then, you are not relying on the database engine to handle and there could be synchronisation troubles, if you really need to handle time intervals that small.
0
 
LVL 2

Expert Comment

by:dslavin
ID: 1081875
I'm not certain, but the operating system might keep track of time down to the millisecond level.  If this is the case, then you might be able to get the Operating System time and store that in the database, rather than Oracle's.

If you are using Oracle Forms to get the date, then you can use a USER_EXIT to execute a C function, or you can use the HOST command to execute a C program to get the time.

If you are using PL/SQL then you can use Oracle FFI (Foreign Function Interface) to get the time from the Operating System.

You could also use a Pro*C API to simultaneously get the current Operating System time and insert the record into the database.
0
 
LVL 1

Expert Comment

by:vulkanr
ID: 1081876
if i recall correctly, there is a function in dbms_util
package that returns the current timestamp. it returns it as
a NUMBER.

unfortunately, i dont have an oracle enviroment available right here, so i cant be more specific, but i KNOW this function exists.
0
 
LVL 2

Author Comment

by:jbiswas
ID: 1081877
Yeah I have considered using a varchar field to store the data coming in, but how do you get the miliisecond timestamp after the data is transferred into Oracle. I mean every time a row is inserted or updated it is important to store the timestamp down to the millisecond level. If a package enables us to do that that would be really great.
0
 
LVL 5

Accepted Solution

by:
Mujeeb082598 earned 200 total points
ID: 1081878
Hi :)

Why not consider using two fields (mydate date, mymillisec number(4)) in your table where the milliseconds are important, u have to do a bit of programming in your applications though.

Save the date as it is in the date field and save the milliseconds in another filed as number.

So when u do the update u update the date field separately and milliseonds field separately, and while displaying u can concatinate the two fileds.

Using two fields will save u from doing extra string manipulation.
0
 
LVL 1

Expert Comment

by:vulkanr
ID: 1081879
i checked.
there is a function - dbms_util.get_time which returns a number
indicating the time in 100'th of seconds.
you can use a trigger to update a field with the time down to
100th of seconds.
no function however returns miliseconds.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question