sqlldr - 未反映加载完成

时间:2014-01-09 17:39:33

标签: sql oracle bash sqlplus sql-loader

我有一个bash脚本(load_data.sh),它调用sqlldr命令将.csv中的数据加载到表(data_import)中。在最近的一次调用中,我注意到即使命令执行完成,该表也不包含.csv文件中的数据。我这样说是因为bash脚本中的后续语句(process_data.sh)试图运行一个抛出错误的存储过程
ORA-01403: no data found

learned提交在文件加载后立即发生。所以,我想知道是什么导致了这个错误以及我将来如何避免它。

以下是我的脚本:

load_data.sh

#!/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

clean.sh/process_data.sh

# 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
(
...
...
)

编辑

  1. 输入文件有8行,两次运行的日志表明已成功插入8行。
  2. 有趣的行为:第二次在同一个文件上运行脚本时脚本运行正常(没有抱怨错误)。因此,在第一次运行期间,sqlldr命令似乎在执行下一个sqlplus命令之前没有完成。

1 个答案:

答案 0 :(得分:0)

如果捕获sqlldr命令的PID并等待它完成,那么您将确定它已完成。您可以将日期戳添加到日志文件或时间戳(如果它每天运行多次)并执行while循环并休眠并检查日志何时打印其最后完成行。然后运行下一步。