MySQL - Load Data Infile with variable path

此生再无相见时 提交于 2019-12-24 01:01:34

问题


I'm having a problem with setting a variable path for putting data into my table. This is how i build my path:

SET @path1 = CONCAT('C:/Projekte/Metrics/DXL_CSV_EXPORT_DATA/', YEAR(NOW()), '_',    MONTH(NOW()), '_', DAY(NOW()), '%', '/_','BeMiko/');`

Every day another Folder is created on the server. I want to automatically import the information from the .csv files from inside these folders each day.

I import data from files with:

LOAD DATA INFILE 
path...
IGNORE INTO TABLE table1 FIELDS TERMINATED BY ';' ENCLOSED BY '"'
LINES TERMINATED BY '<*line_end*>\r\n' IGNORE 1 ROWS;

How do i use the string inside my @path1 variable as path? Or if this is not possible: Are there other ways to solve this problem?


回答1:


Variables can't be used to substitute paths in the LOAD DATA INFILE statement.

Also:

User variables may be used in most contexts where expressions are permitted. This does not currently include contexts that explicitly require a literal value, such as in the LIMIT clause of a SELECT statement, or the IGNORE N LINES clause of a LOAD DATA statement.

  • as seen in the mysql manual


来源:https://stackoverflow.com/questions/25380903/mysql-load-data-infile-with-variable-path

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