mysql加载数据infile where子句

19 mysql load-data-infile

我需要根据某些条件更新表中的现有行和load data infile,这可能吗?

load data infile 'E:/xxx.csv'
into table tld_tod
@aaa, @xxx_date, @ccc
fields terminated by ','
 LINES TERMINATED BY '\r\n'
set xxx = str_to_date(@xxx_date, '%d-%b-%y')
where xxx is not null and aaa=@aaa 

小智 1

在 MySQL 中,可以在更新之前创建触发器。所以在这种情况下我建议使用:

delimiter //
CREATE TRIGGER upd_check BEFORE UPDATE ON table
       FOR EACH ROW
       BEGIN
           IF NEW.xxx IS NOT NULL THEN
               SET NEW.xxx = 0;
           END IF;
       END;//
delimiter ;
Run Code Online (Sandbox Code Playgroud)

创建触发器后,您可以运行 load data infile 而不需要 WHERE。我不确定您的具体要求条件是什么,但请在 BEGIN 和 END 内执行。