Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Insert Time only in field DATE

Re: Insert Time only in field DATE

From: Michel Cadot <micadot{at}altern{dot}org>
Date: Sat, 21 Jul 2007 08:21:03 +0200
Message-ID: <46a1a5cf$0$23786$426a34cc@news.free.fr>

"??Waleed Harbi" <waleed.harbi_at_gmail.com> a écrit dans le message de news: 1184996260.768064.29420_at_w3g2000hsg.googlegroups.com...
| Hello All,
|
| I am trying insert time only in field with data type DATE, but it does
| not work with me as i want and this is what i did as example:
|
| insert into my_table (my_col_date) values
| (to_date('12:00:00','hh:mi:ss'));
|
| When i did this statement oracle save the date for the system without
| time.
|
|
| What is the solution to insert time alone in oracle field?

SQL> create table t (col date);

Table created.

SQL> insert into t values (to_date('12:00:00','hh:mi:ss'));

1 row created.

SQL> select to_char(col,'hh:mi:ss') from t; TO_CHAR(



12:00:00

1 row selected.

But what is the meaning of an hour without a day?

| Do you have another data type for time?
| How I can calculate or compare two field of time? i.e 12:00 + 12:30 OR
| 12:30 - 12:30

Adding/Subtracting 2 dates is meaningless, you likely want to add/subtract 1 date and 1 interval or 2 intervals.
In this case use INTERVAL datatype.

SQL> select interval '12:30' hour to minute from dual; INTERVAL'12:30'HOURTOMINUTE



+00 12:30:00

1 row selected.

SQL> select interval '12:30' hour to minute + interval '12:00' hour to minute from dual; INTERVAL'12:30'HOURTOMINUTE+INTERVAL'12:00'HOURTOMINUTE



+000000001 00:30:00.000000000

1 row selected.

Regards
Michel Cadot Received on Sat Jul 21 2007 - 01:21:03 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US