在SQL Loader命令行

时间:2016-11-08 16:18:49

标签: sql oracle sql-loader

我正在尝试在shell脚本中使用SQL Loader,因此我使用的是命令行参数。我动态创建控制文件,然后在加载后在脚本中删除它。我的问题是我的数据文件有回车符,很多记录被丢弃到.bad。我知道我需要使用" str' \ n'"在指定INFILE之后。但是如何使用命令行执行此操作?

以下是我的代码示例。非常感谢任何帮助。

   LDRFILE=$LOCAL_HOME/data/rmse_loc.ctl
   echo "LOAD DATA " > $LDRFILE
   echo "TRUNCATE "    >> $LDRFILE
   echo "INTO TABLE "R2SCHD.RDF_LOC_HIER"" >> $LDRFILE
   echo "FIELDS TERMINATED BY ',' " >> $LDRFILE
   echo "OPTIONALLY ENCLOSED BY '\"' " >> $LDRFILE
   echo "("  >> $LDRFILE
   echo "LOC, " >> $LDRFILE
   echo "LOC_NAME, " >> $LDRFILE
   echo "DISTRICT, "  >> $LDRFILE
   echo "DISTRICT_NAME, " >> $LDRFILE
   echo "DEFAULT_WH, " >> $LDRFILE
   echo "DEFUALT_WH_NAME, " >> $LDRFILE
   echo "LOC_TYPE, " >> $LDRFILE
   echo "LOC_TYPE_NAME " >> $LDRFILE
   echo ")"  >> $LDRFILE
   sqlldr userid=$CONNECT control=$LDRFILE log=$LOCAL_HOME/log/$PROGRAM_NAME.$INPUT_FILE.$RUN_DATE.log bad=$LOCAL_HOME/error/$PROGRAM_NAME.$INPUT_FILE.$RUN_DATE.bad data=$LOCAL_HOME/data/$INPUT_FILE

以下是数据文件前5行的示例,所有行以CR / LF结尾:

34,"34 CARLISLE 67TH ST",3740,"CARLISLE NORTH",6620363,"DDDC REPLENISHMENT",S,"Store"^M
240,"240 FELTWELL SHOP",7614,"UK EAST",2220671,"GDC REPLENISHMENT",S,"Store"^M
5504,"5504 AM CLASS SIX",3720,"SAM S TEXAS",6620363,"DDDC REPLENISHMENT",S,"Store"^M
5827,"5827 JAC CLASS 6",632,"JACKSON/SHAW",9820580,"DDDC REPLENISHMENT",S,"Store"^M
100081,"100081 EGLIN MCS",944,"EGLIN AFB",6620363,"DDDC REPLENISHMENT",S,"Store"^M

1 个答案:

答案 0 :(得分:0)

问题不在于CR / LF,而是列中的一个值太大了:(。业余错误,我是SQL Loader的新手并且正在查看我自己创建的日志而不是实际的SQL日志:

Record 98: Rejected - Error on table R2SCHD.RDF_LOC_HIER, column LOC_NAME.
ORA-12899: value too large for column "R2SCHD"."RDF_LOC_HIER"."LOC_NAME" (actual: 26, maximum: 25)