本文介绍了在MYSQL LOAD DATA INFILE中参数化文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以在LOAD DATA INFILE中动态指定文件名?可以像例如(语法可能不正确)LOAD DATA INFILE'$ filename'一样对其进行参数化吗?

Is there a way to dynamically specify a file name in the LOAD DATA INFILE? Can it be parameterized like for instance (syntax may be incorrect) LOAD DATA INFILE '$filename'?

推荐答案

或者您可以制作文件的临时副本(例如BATCH):

Or you can make a temporary copy of the file (BATCH example):

LOAD_DATA.bat

LOAD_DATA.bat

COPY %1 TempFileToLoad.csv
mysql --user=myuser --password=mypass MyDatabase < ScriptLoadMyDatabase.sql
DEL TempFileToLoad.csv

SQL(有关信息):

the SQL (for info) :

ScriptLoadMyDatabase.sql

ScriptLoadMyDatabase.sql

load data infile 'TempFileToLoad.csv' IGNORE
into table tLoad
FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '"'
lines terminated by '\r\n'
IGNORE 1 LINES
(@DateCrea, NomClient, PrenomClient, TypeMvt, @Montant, NumeroClient)
set DateCrea = str_to_date(@DateCrea, '%Y-%m-%d'), Montant = (round(@Montant / 1000)*2) ;

完成将指向BAT文件的链接放置在SendTo Windows文件夹中.

And finished to put a link to the BAT file in SendTo windows folder.

这篇关于在MYSQL LOAD DATA INFILE中参数化文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 22:40