2016-02-10 121 views
0

負載SQL INFILE我有一個數據像這樣的純文本文件:與第一列固定寬度

B01-CA This is first data 
Z01  This is second data 
A56-COL This is third data 

所以我想在一個表3列ID,密碼,姓名插入這些數據。

我知道的語法:

load data local infile 'C:/codes.txt' 
into table tbl_test 
fields 
terminated by ' ' 
enclosed by ' ' 
lines 
terminated by '\n' 
(code,name); 

但我怎麼能採取第一個子高達8個charactrs在代碼列,其餘線路直到「\ n」用來列。 id是自動增量。任何想法都會有幫助。

回答

0

我有同樣的問題。 我已經這樣做了:

load data local infile '<file>' into table <table_name> (@row) set code = trim(substr(@row, 0,7)), name = trim(substr(@row, 8)) 

它爲我工作