Use parameters with CTL

大城市里の小女人 提交于 2020-01-25 06:58:45

问题


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 !


回答1:


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



来源:https://stackoverflow.com/questions/4552947/use-parameters-with-ctl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!