Teradata Fastload脚本问题 - 日期未正确格式化错误2665

时间:2012-08-07 20:49:43

标签: sql datetime teradata

我有一个快速加载脚本给我带来了问题。我是teradata的新手,不知道日期应该如何正确格式化。日期列目前格式为:excel(csv)中的“12/31/2011”。

我的脚本如下:

BEGIN LOADING "table"
    ERRORFILES "errors1", "errors2";


SET RECORD VARTEXT ",";


DEFINE PERD_END_RPT_DT   (VARCHAR(20)),  <---- date column returning the error
       RPT_PERD_TYPE_CD  (VARCHAR(20)),
       PERD_NM       (VARCHAR(30)),
       QTR_NUM           (VARCHAR(2)),
       YEAR_NUM          (VARCHAR(4)),
       RPT_PERD_TYPE_NM  (VARCHAR(10)),
       DATA_VLDTN_IND    (VARCHAR(1)),
       EDW_PUBLN_ID      (VARCHAR(18)) 

FILE=C:\pathtofile\file.csv;

INSERT INTO "table" ( PERD_END_RPT_DT, RPT_PERD_TYPE_CD, PERD_NM, QTR_NUM, YEAR_NUM, RPT_PERD_TYPE_NM,
                          DATA_VLDTN_IND, EDW_PUBLN_ID )
    VALUES ( :PERD_END_RPT_DT, :RPT_PERD_TYPE_CD, :PERD_NM, :QTR_NUM, :YEAR_NUM, :RPT_PERD_TYPE_NM,
                          :DATA_VLDTN_IND, :EDW_PUBLN_ID ) ;

END LOADING ;
LOGOFF ;

那么如何格式化日期以及如何修改我的脚本以使其工作?谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

试试这个:

BEGIN LOADING "table"
    ERRORFILES "errors1", "errors2";


SET RECORD VARTEXT ",";


DEFINE PERD_END_RPT_DT   (VARCHAR(20)),  -- date column returning the error
       RPT_PERD_TYPE_CD  (VARCHAR(20)),
       PERD_NM           (VARCHAR(30)),
       QTR_NUM           (VARCHAR(2)),
       YEAR_NUM          (VARCHAR(4)),
       RPT_PERD_TYPE_NM  (VARCHAR(10)),
       DATA_VLDTN_IND    (VARCHAR(1)),
       EDW_PUBLN_ID      (VARCHAR(18)) 

FILE=C:\pathtofile\file.csv;

INSERT INTO "table" ( PERD_END_RPT_DT, RPT_PERD_TYPE_CD, PERD_NM, QTR_NUM, YEAR_NUM, RPT_PERD_TYPE_NM, DATA_VLDTN_IND, EDW_PUBLN_ID )
    VALUES ( CAST(:PERD_END_RPT_DT AS DATE FORMAT 'mm/dd/yyyy') -- Changed here
           , :RPT_PERD_TYPE_CD
           , :PERD_NM
           , :QTR_NUM'
           , :YEAR_NUM
           , :RPT_PERD_TYPE_NM 
           , :DATA_VLDTN_IND
           , :EDW_PUBLN_ID ) ;

END LOADING ;
LOGOFF ;