mysql在where子句中加载数据
我需要根据某些条件使用加载数据文件更新表中的现有行,这可能吗?
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
I need to update existing rows in table with load data infile based on some condition, is this possible?
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以创建临时表,将 CSV 文件中的数据插入到临时表中,最后通过所需的操作和过滤将数据插入到目标表中。
You ca also create a staging table, insert the data from the CSV file into the staging table and then finally insert the data into your target table with the required operations and filtering.
在 MySQL 中,可以在更新之前创建触发器。所以在这种情况下我建议使用:
创建触发器后,您可以运行 load data infile 而无需 WHERE。
我不确定您的具体要求条件是什么,但请在 BEGIN 和 END 内执行。
In MySQL it's possible to create triggers before update. So in this case I suggest to use:
After creating trigger, you can run load data infile without WHERE.
I'm not sure what's your specific required condition, but do it inside BEGIN and END.