The LOAD DATA INFILE command is a flexible way to upload bulk volumes of data and is especially useful for loading data files which have been submitted in a csv format.
LOAD DATA LOCAL INFILE ‘file.csv’ INTO TABLE my_table
FIELDS TERMINATED BY ‘,’
ENCLOSED BY ‘”‘
LINES TERMINATED BY ‘\n’
(name, address, @var1)
set dateOfBirth = STR_TO_DATE(@var1, ‘%d-%b-%y’)
In the above code segment I use the
SET clause, along with a variable to reference the contents of the row at that column. In the column list, I assign the date column to a variable name. I can then use it in the
SET statement to provide the necessary date formatting rule for the data file in question.