I need to use the sql-loader to import some data into a table. Here is my batch-script:
@echo off
for %%i in ("C:\Users\test\*.csv") do (
SET tmpFile=%%~ni
echo load data >controlfile.ctl
echo INFILE 'controlfile.ctl' >>controlfile.ctl
echo into table TABLE_NAME >>controlfile.ctl
echo append >>controlfile.ctl
echo fields terminated by ',' >>controlfile.ctl
echo OPTIONALLY ENCLOSED BY '"' AND '"' >>controlfile.ctl
echo trailing nullcols >>controlfile.ctl
echo ( >>controlfile.ctl
echo COLUMN1 CHAR(4000), >>controlfile.ctl
echo COLUMN2 CHAR(4000), >>controlfile.ctl
echo COLUMN3 CHAR(4000), >>controlfile.ctl
echo FILE_NAME %tmpFile% >>controlfile.ctl
echo ) >>controlfile.ctl
sqlldr db_user/db_pw CONTROL='C:\test\controlfile.ctl' LOG='C:\Users\test\mylog.log' skip=1
)
pause
Normally you have a control-file and a script that executes this file, however you cannot pass parameter to the control-file. IN my case, I want to save the fileName on the column in the table. Therefore I need to create the control-file on the fly, because on this way I can pass the fileName as a parameter (tmpFile)
However, I am stuck and cannot go further.
First, the control-file will be generated however most of the content is missing:
COLUMN1 CHAR(4000
COLUMN2 CHAR(4000),
COLUMN3 CHAR(4000),
FILE_NAME test
)
And secondly, I get this message on my cmd:
The process cannot access the file because it is being used by another process.
Ignore for a moment the second part (or maybe you know exactly why I get this error)...Why is most of the content missing in my control-file? Can someone pls help me...I am stuck and don't know what to do