SQLLOAD應用舉例
sqlload_ctl.sh檔案內容如下:
. ${HOME}/.biconfig
TABNAME=tb_individual_bill
INTCODE=05111
#!/bin/sh
sql_clean() {
sqlplus -s ${loghwods}<
set heading off;
set verify off;
set feedback off;
set show off;
set trim off;
set pages 0;
set concat on;
set lines 300;
set trimspool on;
set trimout on;
whenever sqlerror exit 20;
truncate table ${TABNAME};
exit 0;
EOF
}
infile_list() {
unset FLIST
export FLIST=`find $FDIR -name "*${NOW}*.AVL"`
bb=`echo $FLIST|wc -w |awk '{printf"%sn",$1}'`
if [ $bb -eq 0 ]
then
echo "沒有檔案"
exit 0
fi
>${INFILE_LIST}
for F in ${FLIST}
do
echo "INFILE "${F}"" >> ${INFILE_LIST}
done
}
control_fields() {
sqlplus -s ${loghwods}<
set heading off;
set verify off;
set feedback off;
set show off;
set trim off;
set pages 0;
set concat on;
set lines 300;
set trimspool on;
set trimout on;
spool ${FIELDS_TMP};
/*****************
select decode (rownum, 1, ' ', ' , ')||
rpad (column_name, 33, ' ')||
'"trim(:'||
trim(column_name)||
')"'
from user_tab_columns
where table_name= upper ('${TABNAME}')
order by column_id;
*****************/
SELECT
decode (xh, 1, ' ', ' , ')||
rpad (column_name, 33, ' ')||
rpad('CHAR('|| data_length ||')', 16, ' ')||
'"trim(:'||
trim(column_name)||
')"'
FROM
(
select
RANK() OVER ( PARTITION BY table_name ORDER BY column_id ASC ) AS xh
,column_name
,data_length
from user_tab_columns
where table_name= upper ('${TABNAME}')
) A
ORDER BY A.xh;
select ')' from sys.dual;
spool off;
exit;
EOF
}
control_head() {
echo "LOAD DATA" > ${CTL_HEAD_FILE}
}
control_fix1() {
echo "APPEND" >${CTL_FILE_FIX1}
echo "INTO TABLE ${TABNAME}" >> ${CTL_FILE_FIX1}
echo "FIELDS TERMINATED BY ' '" >> ${CTL_FILE_FIX1}
echo "TRAILING NULLCOLS" >> ${CTL_FILE_FIX1}
echo "(" >> ${CTL_FILE_FIX1}
}
combine_files() {
>${CONTROL_FILE}
cat ${CTL_HEAD_FILE} >> ${CONTROL_FILE}
cat ${INFILE_LIST} >> ${CONTROL_FILE}
cat ${CTL_FILE_FIX1} >> ${CONTROL_FILE}
cat ${FIELDS_TMP} >> ${CONTROL_FILE}
}
init_tmpfile() {
>${CTL_HEAD_FILE}
>${INFILE_LIST}
>${CTL_FILE_FIX1}
>${FIELDS_TMP}
rm -f ${LOG}
rm -f ${BADLOG}
}
clear_tmpfile() {
rm -f ${CTL_HEAD_FILE}
rm -f ${INFILE_LIST}
rm -f ${CTL_FILE_FIX1}
rm -f ${FIELDS_TMP}
}
sqlldr_cmd() {
echo "sqlldr userid=${loghwods} control=${CONTROL_FILE} log=${LOG} bad=${BADLOG} ${LOADS} errors=10000000 bindsize=200000 silent=HEADER direct=TRUE parallel=TRUE readsize=20000000 external_table=NOT_USED columnarrayrows=20000 streamsize=20000000" > ${SQLLDR_CMD}
}
chmod_files() {
chmod +x ${CONTROL_FILE}
chmod +x ${SQLLDR_CMD}
}
if [ $# -ne 2 ]
then
echo "引數:[絕對路徑][日期]"
exit -1;
fi
FDIR=$1
NOW=$2
CONTROL_FILE=${HOME}/ctl/${INTCODE}.ctl
CTL_HEAD_FILE=/tmp/${TABNAME}_$$.hd
INFILE_LIST=/tmp/${TABNAME}_$$.inf
CTL_FILE_FIX1=/tmp/${TABNAME}_$$.fx1
FIELDS_TMP=/tmp/${TABNAME}_$$.fld
SQLLDR_CMD=${HOME}/sload/${INTCODE}.sld
LOG=${logdir}/sload/${INTCODE}${NOW}.log
BADLOG=${logdir}/sload/bad/${INTCODE}${NOW}bad.log
# LOADS="load=500"
init_tmpfile;
sql_clean;
RETCODE=$?
##
# 強化檢查
if [ ${RETCODE} -ne 0 ]
then
echo "錯誤A"
exit 20;
fi
control_head;
infile_list ${TABNAME} ${FDIR} ${NOW}
control_fix1;
control_fields;
combine_files;
clear_tmpfile;
sqlldr_cmd;
cat ${CONTROL_FILE}
cat ${SQLLDR_CMD}
chmod_files;
sql_clean;
timex ${SQLLDR_CMD}
if [ ! -f ${LOG} ]
then
echo "${LOG}沒找到";
exit -1;
fi
cp ${LOG} /tmp/${INTCODE}.log
if grep "successfully" ${LOG}
then
LOGNUM=`grep "successfully" ${LOG}|awk '{print $1}'`;
else
LOGNUM=0
fi
if [ -f ${BADLOG} ]
then
BADNUM=`wc -w ${BADLOG}|awk '{print $1}'`;
else
BADNUM=0;
fi
if [ ${LOGNUM} -eq 0 -o ${LOGNUM} -le ${BADNUM} ]
then
exit 20; #裝載失敗
fi
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/77311/viewspace-1020221/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 設計模式應用舉例設計模式
- golang Context應用舉例GolangContext
- Lotus C API Extension Manager 應用舉例API
- oracle rollup,cube子句的應用舉例;Oracle
- AC-DMIS測量程式應用舉例
- 並查集(Union-Find) 應用舉例並查集
- WebSphere Remote Server 簡介及其應用舉例WebREMServer
- 正規表示式理解及簡單應用舉例
- 樂觀鎖與悲觀鎖及應用舉例
- 再談多型--多型的應用舉例: (轉)多型
- R語言中管道符號 %>% 的應用 及 舉例R語言符號
- sqlloadSQL
- 用SQLLOAD匯入CLOB資料SQL
- 並查集(Union-Find) 應用舉例 --- 基礎篇並查集
- 輕鬆搭建基於 Serverless 的 Go 應用(Gin、Beego 舉例)ServerGo
- Python偏函式應用舉例-路燈指示牌Python函式
- mssql sqlserver in 關鍵字在值為null的應用舉例SQLServerNull
- 常用的Linux可插拔認證模組(PAM)應用舉例Linux
- Android底層字元傳遞給上層應用舉例Android字元
- 執行緒池的實現原始碼及應用舉例執行緒原始碼
- 自定義構建互動式SSH應用程式,用Python為大家舉例Python
- Java在量化投資等金融業的關鍵應用舉例 - oracleJavaOracle
- sysconf()函式應用舉例:檢視CPU及記憶體資訊函式記憶體
- oracle rollup,cube子句的應用舉例(可以實現總計,小計)Oracle
- uva 11997 priority_queue 應用舉例(超省時間!!!)
- 舉例說明你對尾遞迴的理解,有哪些應用場景遞迴
- JAVA反射舉例Java反射
- 盒模型舉例模型
- 死鎖-舉例
- 吳恩達機器學習筆記 —— 19 應用舉例:照片OCR(光學字元識別)吳恩達機器學習筆記字元
- 單例模式中為什麼用列舉更好單例模式
- dd應用例項
- shell指令碼舉例指令碼
- java 正則舉例Java
- ”innerHTML“的應用例項HTML
- hive應用例項1Hive
- 智慧Web應用例項Web
- calico docker 應用例項Docker