Use parameters with CTL

2019-08-17 01:25发布

I am using a CTL file to load data stored in a file to a specific table in my Oracle database. Currently, I launch the loader file using the following command line:

sqlldr user/pwd@db data=my_data_file control=my_loader.ctl

I would like to know if it is possible to use specify parameters to be retrieved in the CTL file.

Also, is it possible to retrieve the name of the data file used by the CTL to fill the table ?I also would like to insert it for each row. I currently have to call a procedure to update previously inserted records.

Any help would be appreciated !

标签: oracle ctl
1条回答
We Are One
2楼-- · 2019-08-17 02:18

As I know don't have any way to pass parametter as variable in ctrl.
But You can use constant in ctl and modify clt file to change that constant value (in ctl file content) for every loading times.

Edit: more specific.

my_loader.ctl:

--options
load data
infile 'c:\$datfilename$' --this is optional, you can specify here or from command line

into table mytable
fields....
(
datafilename constant '$datfilename$', -- will be replace by real datafname each load
datacol1  char(1),
....
)

dataload.bat: assume that $datfilename$ is the text will be replace by datafile's name.

::sample copy
copy my_loader.ctl my_loader_temp.ctl

::replace the name of datafile (mainly the content to load into table's data column)
findandreplace my_loader_temp.ctl "$datafilename$" "%1"

::load
sqlldr user/pwd@db data=%1 control=my_loader_temp.ctl
::or with data be obmitted if you specified by infile in control file.
sqlldr user/pwd@db control=my_loader_temp.ctl

using: dataload.bat mydatafile_2010_10_10.txt

查看更多
登录 后发表回答