繁体   English   中英

将日期和时间插入oracle11g中的表

[英]inserting date and time into a table in oracle11g

我有两个表,其中一个表中有一个包含日期和时间的列。类型为DATE。

我应该在另一张表中使用哪种类型将前一张表的带有日期和时间的列的值插入该表中。

我尝试过DATE BUT THE TIME GETS CHANGED.i我不想使用字符串。

我认为您存在显示问题,或者您不正确地复制了日期字段。 它应该工作。 看我的例子:

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;

输出量

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.

它不会自动为您显示时间,但会被截断。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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