带有变量的 sqlldr 控制文件字段

sqlldr control file fileds with variable

infile ‘c:sandeep.txt’
truncate
into table emp
fields TERMINATED BY “|”
trailing nullcols(
column_name constant “${variable}”,
)

sqlldr 运行 通过 shell 脚本,是否有任何方法将变量传递给 sqlldr 并使字段使用我传递给它的内容?

这个怎么样:

#!/bin/sh
#-- setup
col_name=MY_COL_NAME
#-- create the control file.  Have to escape the double-quotes
rm myloader.ctl      2>/dev/null
echo infile ‘c:sandeep.txt’                >> myloader.ctl
echo truncate                              >> myloader.ctl
echo into table emp                        >> myloader.ctl
echo fields TERMINATED BY \"\|\"            >> myloader.ctl
echo "trailing nullcols("                  >> myloader.ctl
echo column_name constant \"${col_name}\", >> myloader.ctl
echo ")"                                   >> myloader.ctl
#
#-- check the results
cat myloader.ctl
#-- run sqlldr
sqlldr control=myloader.ctl