sqlloader加载unix时间戳

sqlloader loading unix timestamp

我似乎无法使用 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',

如果您的输入如下:

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 想要添加到日期的时间)

编辑:

对于这样的 table:

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"
)

输出(select * 来自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