Loading fixed-width, space delimited .txt file into mySQL

自作多情 提交于 2019-12-03 15:32:28

These are what we call "fixed-width" records and LOAD DATA doesn't play well with them. Options:

  1. Clean up data in Excel first, or
  2. Load up the data to a temp table with only 1 column, shoving an entire text row into that column. Then you can use SUBSTR() and TRIM() to slice out the columns you need into the final table.
  3. Or with user variables (@row) you can do it all within the LOAD DATA statement.
LOAD DATA LOCAL INFILE 
'/some/Path/segmentation.txt' 
INTO TABLE clip
(@row)
SET slideNum = TRIM(SUBSTR(@row,1,4)),
    startTime = TRIM(SUBSTR(@row,5,13)),
    endTime = TRIM(SUBSTR(@row,18,13))
;
    LOAD DATA
CHARACTERSET AL32UTF8
INFILE 'DCF Master 14APR2013 VSPCFM_reduced size.txt'
INTO TABLE EMPLOYEE3
(
a = TRIM(SUBSTR(@row,1,11)),
b = TRIM(SUBSTR(@row,33,38)),
c = TRIM(SUBSTR(@row,70,86))
)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!