2012-11-12 47 views
1

我的控制文件是的Oracle SQL * Loader的時間戳是錯誤

ACCESS_TIME TERMINATED BY "" "TO_TIMESTAMP_TZ(:ACCESS_TIME,'YYYY/MM/DD HH24:MI:SS:FF TZR')" 

數據文件

2012/11/12 15:18:00:765 CST 

但是當我運行SQL * Loader來提交數據,在數據庫中ACCESS_TIME不匹配數據文件。

2012/11/13 05:18:00:765000000 

回答

0

如果你看到這種行爲,則表列必須是時間戳與本地時區,你在新加坡等(GMT +8),例如:

SQL> alter session set time_zone='+08:00'; 

Session altered. 

SQL> create table test (access_time timestamp with local time zone); 

Table created. 

SQL> host sqlldr test/test control=/tmp/load.ctl log=/tmp/load.log 

SQL*Loader: Release 11.2.0.1.0 - Production on Mon Nov 12 13:26:14 2012 

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. 

Commit point reached - logical record count 2 

SQL> select * from test; 

ACCESS_TIME 
--------------------------------------------------------------------------- 
13-NOV-12 05.18.00.765000 

SQL> alter session set time_zone='-06:00'; 

Session altered. 

SQL> select * from test; 

ACCESS_TIME 
--------------------------------------------------------------------------- 
12-NOV-12 15.18.00.765000 

SQL> host cat /tmp/load.ctl 
load data 
infile * 
replace 
into table test 
( ACCESS_TIME terminated by "" "TO_TIMESTAMP_TZ(:ACCESS_TIME,'YYYY/MM/DD HH24:MI:SS:FF TZR')" 
) 
begindata 
2012/11/12 15:18:00:765 CST 

,如果你想保留CST部分,而不是將其轉換,然後將您的表定義爲TIMESTAMP WITH TIME ZONE。

SQL> create table test (access_time timestamp with time zone); 

Table created. 

SQL> host sqlldr test/test control=/tmp/load.ctl log=/tmp/load.log 

SQL*Loader: Release 11.2.0.1.0 - Production on Mon Nov 12 13:27:56 2012 

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. 

Commit point reached - logical record count 2 

SQL> select * from test; 

ACCESS_TIME 

--------------------------------------------------------------------------- 
12-NOV-12 15.18.00.765000 CST 
0

做一個:

select SESSIONTIMEZONE from dual; 

您插入在中部標準時間數據。當您選擇數據時,它可能會顯示在您的會話(本地)時區中。