0

我对 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 表

4

1 回答 1

0

使用相同的脚本,日期时间应更改以下内容: (1) 列类型应为时间戳。Timestamp(0) 将以样本数据为基础。(2) 在 fastload DEFINE 中,该字段的长度应为 18。 (3) 在 fastload insert 中,您可以使用以下代码:

:file_CREATE_TS(format 'DDMMMYYYY:HH:MI:SS')
于 2019-12-11T09:20:52.357 回答