我有以下文本文件: 
030603035435103830000000000305昆山市燃料有限责任公司       802713004948510383236 
030603035435103830000000000105湖北市天明经贸有限公司       902713004348510383797 
      这个文本文件没有分隔符,但是各个字段之间的宽度是固定的。在Excel中用文本导入的方式,可以采用固定宽度的方式,将各个字段区分开来,导入表中。但现在不知道MySQL 如何导入这种数据。 
   希望导入指定的表后是这种情况: 
|--------------------+-------------------------------|--------------------------------------------|---------|-------------------| 
| jgm(12个字符) | dwbm(18个字符)         |  dwmd(26个字符)                          | fhm(4)| dmdc(11)      | 
|--------------------+-------------------------------|--------------------------------------------|---------|-------------------| 
|030603035435|103830000000000105|湖北市天明经贸有限公司       |80271|30043485103| 
|--------------------+-------------------------------|--------------------------------------------|---------|-------------------| 
|030603035435|103830000000000105|湖北市天明经贸有限公司       |90271|30043485103| 
|--------------------+-------------------------------|--------------------------------------------|---------|-------------------| 

解决方案 »

  1.   

    用 load data infile .... set dwbm=SUBSTRING(@xx,13,18),...
      

  2.   

    当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
    http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
    http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html8、如何给分和结贴?
    http://community.csdn.net/Help/HelpCenter.htm#结帖
      

  3.   

       当我执行以下语句时,
    load data infile 'd:\cx1.txt' into table cx1 fields terminated by "" lines terminated by "\n"  set xyh=(@xx,11,20),dwmc(@xx,21,24),zsjg(@xx,55,5)   出现提示:
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(@xx,21,24),zsjg(@xx,55,5)' at line 1
      

  4.   

    楼主需要学会看MYSQL的手册中的语法说明。MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.htmlmysql> load data infile 'C:\\cx1.txt'
        -> into table cx1 (@xx)
        -> set jgm=SUBSTRING(@xx,1,12),
        -> dwbm=SUBSTRING(@xx,13,18),
        -> dwmd=SUBSTRING(@xx,31,26),
        -> fhm=SUBSTRING(@xx,47,4),
        -> dmdc=SUBSTRING(@xx,51,11);
    Query OK, 2 rows affected (0.00 sec)
    Records: 2  Deleted: 0  Skipped: 0  Warnings: 0mysql> select * from cx1;
    +--------------+--------------------+----------------------------+------+-------------+
    | jgm          | dwbm               | dwmd                       | fhm  | dmdc      |
    +--------------+--------------------+----------------------------+------+-------------+
    | 030603035435 | 103830000000000305 | 昆山市燃料有限责任公司     | 任公 | 司   80 |
    | 030603035435 | 103830000000000105 | 湖北市天明经贸有限公司     | 限公 | 司   90 |
    +--------------+--------------------+----------------------------+------+-------------+
    2 rows in set (0.00 sec)mysql>