我正在尝试使用SQLLDR将.csv文件加载到表中。但是,它出现了EXIT ERROR CODE 2,我无法理解。
#!/bin/bash
. ~/.bash_profile
. $CONFIGFILE
CTLFILE=$ctl_dir/Load_Account_Metadata.ctl
INFILE=$data_dir/NGLAcounts.csv
LOGFILE=$log_dir/Load_Account_Metadata.log
CTLLOGFILE=$log_dir/Load_Account_Metadata.log
BADFILE=$log_dir/Load_Account_Metadata.bad
DISCARDFILE=$log_dir/Load_Account_Metadata.dsc
SQLERR=0
USERID=$pstgusr'/'$pstgpwd'@'$pstgtns
echo "`date` - Start Loading into table NGLAccounts " > $LOGFILE
#echo 'USERID Staging: '$USERID >> $LOGFILE
if [ -f $CTLLOGFILE ]
then
rm -f $CTLLOGFILE
fi
if [ -f $BADFILE ]
then
rm -f $BADFILE
fi
if [ -f $DISCARDFILE ]
then
rm -f $DISCARDFILE
fi
sqlldr userid=$USERID control=$CTLFILE data=$INFILE log=$CTLLOGFILE bad=$BADFILE discard=$DISCARDFILE
SQLERR=$?
echo "`date` - Return Code of SQLLDR to load into table NGLAccounts : $SQLERR " >> ${LOGFILE}
echo " " >> $LOGFILE
echo "******************************* SQLLDR Log Starts **********************************" >> $LOGFILE
echo " " >> $LOGFILE
cat $CTLLOGFILE >> $LOGFILE
echo " " >> $LOGFILE
echo "******************************* SQLLDR Log Ends **********************************" >> $LOGFILE
echo " " >> $LOGFILE
if [ -f $CTLLOGFILE ]
then
rm -f $CTLLOGFILE
fi
if [ $SQLERR -ne 0 ]
then
echo "`date` - SQLLDR to load into table NGLAccounts failed. Exiting with error code $SQLERR." >> ${LOGFILE}
exit $SQLERR
fi
echo " " >> $LOGFILE
echo " " >> $LOGFILE
echo " " >> $LOGFILE
echo "`date` - Finished loading into table NGLAccounts" >> $LOGFILE
这是错误消息。
if [ "$ERR_CODE" -ne 0 ];
then
echo "`date` - SQLLDR to load into table NGLAccounts failed. Exiting with error code $SQLERR. $ERR_CODE" >> $LOGFILE
exit $ERR_CODE
fi
+ '[' 2 -ne 0 ']'
date
++ date
+ echo 'Wed Jun 28 00:02:55 AEST 2017 - SQLLDR to load into table NGLAccounts failed. Exiting with error code . 2'
+ exit 2
通过使用SQLLDR,我们可以将.csv文件加载到指定的表。