我有一个包含以下架构的表
+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| NDB_No | char(5) | NO | PRI | NULL | |
| FdGrp_Cd | char(4) | NO | MUL | NULL | |
| Long_Desc | char(200) | NO | | NULL | |
| Shrt_Desc | char(60) | NO | | NULL | |
| ComName | char(100) | YES | | NULL | |
| ManufacName | char(65) | YES | | NULL | |
| Survey | char(1) | YES | | NULL | |
| Ref_desc | char(135) | YES | | NULL | |
| Refuse | decimal(2,0) | YES | | NULL | |
| SciName | char(65) | YES | | NULL | |
| N_Factor | decimal(4,2) | YES | | NULL | |
| Pro_Factor | decimal(4,2) | YES | | NULL | |
| Fat_Factor | decimal(4,2) | YES | | NULL | |
| CHO_Factor | decimal(4,2) | YES | | NULL | |
+-------------+--------------+------+-----+---------+-------+
尝试导入此行时
01002^0100^Butter, whipped, with salt^BUTTER,WHIPPED,W/ SALT^NULL^NULL^Y^NULL^0^NULL^6.38^NULL^NULL^NULL
我遇到了错误
1366 Incorrect decimal value: 'NULL' for column 'Pro_Factor'
1366 Incorrect decimal value: 'NULL' for column 'Fat_Factor'
1366 Incorrect decimal value: 'NULL' for column 'CHO_Factor'
数据导入为0.00
'01002', '0100', 'Butter, whipped, with salt', 'BUTTER,WHIPPED,W/ SALT', 'NULL', 'NULL', 'Y', 'NULL', '0', 'NULL', '6.38', '0.00', '0.00', '0.00'
目前,我正在使用MySQLWorkbench从本地文件导入数据
LOAD DATA LOCAL INFILE 'FOOD_DES.txt'
INTO TABLE usda_sr28.FOOD_DES
FIELDS TERMINATED BY '^'
LINES TERMINATED BY '\n';
答案 0 :(得分:0)
如果您使用的是load data infile
,则可以使用set
:
load data infile . . .
(ndb_no, . . ., @pro, @fat, @cho, . . .)
set pro_factor = nullif(@pro, 'NULL'),
fat_factor = nullif(@fat, 'NULL'),
cho_factor = nullif(@cho, 'NULL')
documentation有更多详情。