1

我的控制文件是

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
4

2 回答 2

0

做一个:

select SESSIONTIMEZONE from dual;

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

于 2012-11-12T08:59:21.773 回答
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
于 2012-11-12T13:27:45.020 回答