MySQL从txt更新数据

MySQL从txt更新数据

#创建临时表
CREATE TEMPORARY TABLE t1 (
	field_name1 INT,
	field_name2 VARCHAR (20)
);
#导入数据到临时表
LOAD DATA LOCAL INFILE 'C:/xxx.txt' REPLACE INTO TABLE t1 CHARACTER
SET utf8 FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' IGNORE 1 LINES (field_name1,field_name2,@val3);

#去除换行符和回车符
UPDATE t1
SET field_name2 = REPLACE (
	REPLACE (field_name2, CHAR(10), ''),
	CHAR (13),
	''
);
#更新数据
UPDATE t2,
 t1
SET t2.field_name2 = (
	CASE t1.field_name2
	WHEN '低危' THEN
		1
	WHEN '中危' THEN
		2
	WHEN '高危' THEN
		3
	WHEN '常规' THEN
		4
	END
),
 t2.field_name3 = @val3
WHERE
	t2.field_name1 = t1.field_name1
  • char(10): 换行符
  • char(13): 回车符
上一篇:2021-10-01


下一篇:elementUI表单校验动态添加校验规则