3 回答

TA貢獻2039條經(jīng)驗 獲得超8個贊
這將做你想要的。它將第四個字段讀入局部變量,然后將實際字段值設(shè)置為NULL,如果局部變量最終包含空字符串:
LOAD DATA infile '/tmp/testdata.txt'
INTO TABLE moo
fields terminated BY ","
lines terminated BY "\n"
(one, two, three, @vfour, five)
SET four = nullif(@vfour,'')
;
如果它們都可能是空的,那么你將它們?nèi)孔x入變量并有多個SET語句,如下所示:
LOAD DATA infile '/tmp/testdata.txt'
INTO TABLE moo
fields terminated BY ","
lines terminated BY "\n"
(@vone, @vtwo, @vthree, @vfour, @vfive)
SET
one = nullif(@vone,''),
two = nullif(@vtwo,''),
three = nullif(@vthree,''),
four = nullif(@vfour,'')
;

TA貢獻1821條經(jīng)驗 獲得超6個贊
根據(jù)數(shù)據(jù)庫配置,行為會有所不同。在嚴(yán)格模式下,這會拋出錯誤,否則會發(fā)出警告。以下查詢可用于標(biāo)識數(shù)據(jù)庫配置。
mysql> show variables like 'sql_mode';
添加回答
舉報