Solved

How to handle milliseconds in Oracle

Posted on 1998-10-08
9
14,257 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
  • 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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now