简体   繁体   中英

inserting date and time into a table in oracle11g

i have two tables in which i have a column containing both date and time in one of the table.the type is DATE.

what type should i use in the other table to insert the values of the former table's column with date and time into this table.

i tried DATE BUT THE TIME GETS CHANGED.i dont want to use string.

I think you have a displaying problem or you incorrectly copy the date field over. It should work. See my example:

set line 250
create table table1 (dt date);
insert into table1 values (to_date('24/11/2014 23:01','DD/MM/YYYY HH24:MI'));
insert into table1 values (to_date('25/11/2014 11:02','DD/MM/YYYY HH24:MI'));
create table table2 (dt date);
select * from table1;
select to_char(dt,'DD-MM-YYYY HH24:MI:SS') from table1;
insert into table2  select * from table1;
select * from table2;
select to_char(dt,'DD-MM-YYYY HH24:MI:SS') from table2;
drop table table1;
drop table table2;

Output

Table created.
1 row created.
1 row created.
Table created.

DT       
---------
24-NOV-14
25-NOV-14

2 rows selected.

TO_CHAR(DT,'DD-MM-YYYYHH24:MI:SS')
----------------------------------
24-11-2014 23:01:00               
25-11-2014 11:02:00               

2 rows selected.
2 rows created.

DT       
---------
24-NOV-14
25-NOV-14

2 rows selected.

TO_CHAR(DT,'DD-MM-YYYYHH24:MI:SS')
----------------------------------
24-11-2014 23:01:00               
25-11-2014 11:02:00               

2 rows selected.
Table dropped.
Table dropped.

It does not automatically show you the time but truncates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM