我对 teradata 相当陌生。我正在尝试读取具有 create_date 列作为日期时间的 csv 文件,尝试将文件导入 teradata 临时表但无法成功。请帮我解决问题。我附上了我开发的示例脚本,它可以很好地处理日期值
HandleTmpTable()
{
bteq <<ENDSQL
.LOGON $TARGET_DB/$TUSER,$TPWD;
/* Drop the temporary tables */
DROP TABLE ${TTMPDB}.test;
/* Create the temporary table test */
CREATE TABLE ${TTMPDB}.test,
NO FALLBACK,
NO BEFORE JOURNAL,
NO AFTER JOURNAL
(
NUMBER VARCHAR(35) NOT NULL,
NAME CHAR(4) NOT NULL,
PROGRAM VARCHAR(20),
CODE CHAR(4),
C_NAME VARCHAR(255),
CO_NAME VARCHAR(50),
CREATE_DATE date format 'YYYY/MM/DD',
UPDATE_DATE date format 'YYYY/MM/DD',
EXCLUDE_IND CHAR(1) ,
NUMBER VARCHAR(40),
FLAG SMALLINT,
NG_FLAG SMALLINT
);
.IF ERRORCODE <> 0 THEN .EXIT ERRORCODE;
.QUIT 0;
ENDSQL
if [ $? -ne 0 ]
then
Error "Unable to create the temporary table"
fi
Log "Temporary tables created successfully"
}
ImportFiles()
{
bteq <<ENDSQL
LOGON $TARGET_DB/$TUSER,$TPWD;
DROP TABLE ${TTMPDB}.test_err1;
DROP TABLE ${TTMPDB}.test_err2;
ENDSQL
fastload <<ENDSQL
.SESSIONS ${TFLSESS};
.ERRLIMIT 1;
.LOGON $TARGET_DB/$TUSER,$TPWD;
SET RECORD VARTEXT ",";
DEFINE
file_NUMBER (VARCHAR(35)),
file_NAME (VARCHAR(4)),
file_PROGRAM (VARCHAR(20)),
file_CODE (VARCHAR(4)),
file_C_NAME (VARCHAR(255)),
file_CO_NAME (VARCHAR(50)),
file_CREATE_DATE (VARCHAR(10)),
file_UPDATE_DATE (VARCHAR(10)),
file_EXCLUDE_IND (VARCHAR(1)),
file_NUMBER (VARCHAR(40)),
file_FLAG (VARCHAR(6)),
file_NG_FLAG (VARCHAR(6))
FILE=test.csv;
SHOW;
BEGIN LOADING ${TTMPDB}.test
ERRORFILES ${TTMPDB}.test_err1, ${TTMPDB}.test_err2
CHECKPOINT 25000000;
INSERT INTO ${TTMPDB}.test
(
:file_NUMBER,
:file_NAME,
:file_PROGRAM,
:file_CODE,
:file_C_NAME,
:file_CO_NAME,
:file_CREATE_DATE ,
:file_UPDATE_DATE ,
:file_EXCLUDE_IND,
:file_NUMBER,
:file_FLAG,
:fileNG_FLAG
);
END LOADING;
ENDSQL
if [ $? -ne 0 ]
then
Error "Unable to Load the temporary table"
else
rm -f test.csv
fi
Log "Temporary tables loaded successfully"
}
样本数据:
FC-A,FC,Fraud,AA,AAAA,,17JAN2019:00:00:00,17JAN2019:00:00:00,N,,,
FC-B,FC,Fraud,BB,BBBBB,,17JAN2019:00:00:00,17JAN2019:00:00:00,N,,,
FC-C,FC,Fraud,CC,CCCCC,,17JAN2019:00:00:00,17JAN2019:00:00:00,N,,,
FC-D,FC,Fraud,DD,DDDDD,,17JAN2019:00:00:00,17JAN2019:00:00:00,N,,,
FC-E,FC,Fraud,EE,EEEEE,,17JAN2019:00:00:00,17JAN2019:00:00:00,N,,,
FC-F,FC,Fraud,FF,FFFFF,,17JAN2019:00:00:00,17JAN2019:00:00:00,N,,,
让我知道如何从 csv 读取和写入 create_date 和 update_date 列的日期时间值到 teradate 表