sqlloader加载unix时间戳

时间:2017-11-14 16:57:02

标签: oracle sql-loader

我似乎无法使用SQLLDR加载unix时间戳。

load data infile 'AST_BusinessService_export.csv' 
append into table ccp.services_temp 
 fields terminated by ',' optionally enclosed by '"' TRAILING NULLCOLS    
 (NAME, SHORT_DESCRIPTION, CREATE_DATE EXPRESSION "(cast(:CREATE_DATE)as date) - TO_DATE('01/01/1970 00:00:00', 'MM-DD-YYYY HH24:MI:SS')) *
24 * 60 * 60")

我想传递

TEST-CI-GO,TIER2_H1_2 FW,1233817523

我收到的错误是SQL*Loader-291: Invalid bind variable CREATE_DATE in SQL string for column CREATE_DATE.

更新

load data infile 'AST_BusinessService_export.csv'
append into table ccp.services_temp
 fields terminated by ',' optionally enclosed by '"' TRAILING NULLCOLS
 (NAME, SHORT_DESCRIPTION, CREATE_DATE EXPRESSION to_date('19700101', 'YYYYMMDD') + ( 1 / 24 / 60 / 60 ) * CREATE_DATE

错误为Expecting SQL string, found "to_date". (NAME, SHORT_DESCRIPTION, CREATE_DATE EXPRESSION to_date('19700101',

1 个答案:

答案 0 :(得分:1)

如果您的输入如下:

TEST-CI-GO,TIER2_H1_2 FW,1233817523

我相信您希望通过执行以下操作转换为日期:

select to_date('19700101', 'YYYYMMDD') + ( 1 / 24 / 60 / 60 ) * 1233817523
from dual;

输出:

2/5/2009 7:05:23 AM

所以从纪元开始并添加那么多秒(转换为几天以来Oracle想要添加到日期的日子)

编辑:

对于这样的表:

create table test_unixdate
(
id number,
secs_since_epoch number,
converted_date date
);

这样的数据:

1,1233817521
2,1243817522
3,1253817523
4,
5,1263817525

您的sqlldr可能如下所示:

LOAD DATA
infile 'test_unixdate.csv'
badfile 'test_unixdate.bad'
discardfile 'test_unixdate.dis'
APPEND
INTO TABLE test_unixdate
Fields terminated by ","
Optionally enclosed by '"'
trailing nullcols
(
id nullif id=blanks,
secs_since_epoch nullif secs_since_epoch=blanks,
converted_date "to_date('19700101', 'YYYYMMDD') + ( 1 / 24 / 60 / 60 ) * :secs_since_epoch"
)

输出(从test_unixdate中选择*):

1   1233817521  2/5/2009 7:05:21 AM
2   1243817522  6/1/2009 12:52:02 AM
3   1253817523  9/24/2009 6:38:43 PM
4       
5   1263817525  1/18/2010 12:25:25 PM