问题
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