Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL time data type

I'm looking to store just a time value in a number of columns, but I'm unsure what data type I have to use? There is currently TIMESTAMP in place, but this seems to store date as well and is useless if I'm trying to store a recorded time from a race.

Any ideas, I've searched around and can't find what I'm looking for.

Thank you for reading!

like image 467
Max Avatar asked Jan 21 '26 11:01

Max


2 Answers

The elapsed time for a race should be stored in an INTERVAL DAY TO SECOND.

SQL> create table runner(
  2    runner_id number primary key,
  3    runner_name varchar2(100),
  4    runner_time interval day to second
  5  );

Table created.

SQL> insert into runner
  2    values( 1, 'Justin', numtodsinterval( 250, 'second' ) );

1 row created.

SQL> select *
  2    from runner;

 RUNNER_ID RUNNER_NAME          RUNNER_TIME
---------- -------------------- ------------------------------
         1 Justin               +00 00:04:10.000000
like image 89
Justin Cave Avatar answered Jan 23 '26 01:01

Justin Cave


TIMESTAMP and DATETIME aren't appropriate here. What you're trying to store isn't a single point in time, but an interval of time. Oracle 9i and later have support for such intervals. Try using INTERVAL DAY TO SECOND:

INTERVAL '3 12:30:06.7' DAY TO SECOND(1)

Reference: http://www.techrepublic.com/article/master-oracles-time-interval-datatypes/6085801

like image 31
ean5533 Avatar answered Jan 23 '26 01:01

ean5533



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!