我有一个bash脚本(load_data.sh
),它调用sqlldr命令将.csv中的数据加载到表(data_import
)中。在最近的一次调用中,我注意到即使命令执行完成,该表也不包含.csv文件中的数据。我这样说是因为bash脚本中的后续语句(process_data.sh
)试图运行一个抛出错误的存储过程
ORA-01403: no data found
。
我learned提交在文件加载后立即发生。所以,我想知道是什么导致了这个错误以及我将来如何避免它。
以下是我的脚本:
#!/usr/bin/bash -p
# code here #
if [[ -f .st_running ]]
then
echo "Exiting as looks like another instance of script is running"
exit
fi
touch .st_running
# ... #
# deletes existing data in the table
./clean.sh
sqlldr user/pwd@host skip=1 control=$CUR_CTL.final data=$fpath log=${DATA}_data.log rows=10000 direct=true errors=999
# accesses the newly loaded data in the table and processes it
./process_data.sh
rm -f .st_running
# code here #
# ... #
sqlplus user/pwd@host <<EOF
set serveroutput on
begin
schema.STORED_PROC;
commit;
end;
/
exit;
EOF
# code here #
# ... #
STORED_PROC 由process_data.sh运行:
SELECT count(*) INTO l_num_to_import FROM data_import;
IF (l_num_to_import = 0) THEN RETURN;
END IF;
/* the error (`ORA-01403: no data found`) happens at this statement: */
SELECT upper(name) INTO name FROM data_import WHERE ROWNUM = 1;
LOAD DATA
APPEND
INTO TABLE DATA_IMPORT
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
...
...
)
答案 0 :(得分:0)
如果捕获sqlldr命令的PID并等待它完成,那么您将确定它已完成。您可以将日期戳添加到日志文件或时间戳(如果它每天运行多次)并执行while循环并休眠并检查日志何时打印其最后完成行。然后运行下一步。