MySQL Forums
Forum List  »  Newbie

Re: Using a Parameter in Load Data Infile Command (Instead of direct filename)
Posted by: Dhaval Sheth
Date: October 22, 2009 01:07AM

Hello All,

I did find a way to provide parameters to load data infile command:

This is how it goes

I have 2 batch files

The master batch file will capture the input file name temporarily and will run a for loop till all the files are called from capture_input_file.txt

Inside for loop the file_names will be called 1 at a time and passed as parameters in the form of C:\\Input\\%%B

master.bat:

dir /b | find /I "input_file.txt" > C:\capture_input_file.txt
FOR /f %%B IN (C:\capture_input_file.txt) DO (echo %%B
call child.bat C:\\Input\\%%B
)

After reaching child batch file, the parameter sent in the form of C:\\Input\\%%B from master batch will be taken as %1 in child batch and this will help to load data into table

child.bat:

mysql -u uname --password=passwd schema_name -e "load data infile '%1' into table table_name fields terminated by '|' lines terminated by '\n' ignore 1 lines (@dummy1, @dummy2) set coln1 = trim(@dummy1),coln2 =trim(@dummy2);

I hope i am able to explain the details.

Let me know if any doubts.

Thanks,
Dhaval

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.