Oracle SQL * Loader时间戳是错误的

时间:2012-11-12 07:45:48

标签: 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

2 个答案:

答案 0 :(得分:0)

做一个:

select SESSIONTIMEZONE from dual;

您在中央标准时间插入数据。当您选择数据时,它可能会显示在会话(本地)时区中。

答案 1 :(得分: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