简体   繁体   English

LOAD DATA INFILE字段终止于

[英]LOAD DATA INFILE fields terminated by

I have searched through this forum but I didn't find anything related to this particular problem I'm facing with. 我在这个论坛上进行了搜索,但没有发现与所面临的这个特定问题相关的任何内容。 Namely, I have a text file which I want to transfer to MySQL db, I'm using PHP for scripting. 即,我有一个文本文件要传输到MySQL数据库,我正在使用PHP编写脚本。

What I want to know is can I by any chance use multiple delimiters in the FIELDS TERMINATED BY parameter: 我想知道的是,我是否可以在FIELDS TERMINATED BY参数中使用多个定界符:

LOAD DATA INFILE '$file' 加载数据文件'$ file'

INTO TABLE $my_table 到表$ my_table

FIELDS TERMINATED BY ';' 以';'结尾的字段

LINES TERMINATED BY '\\r\\n'"; 以'\\ r \\ n'“结尾的行;

My text file looks like this: 我的文本文件如下所示:

11;111111;;1111111;;;;;;1111;;;;11111;;1111111111;111111111;;;111; 11; 111111 ;; 1111111 ;;;;; 1111 ;;;; 11111 ;; 1111111111; 111111111 ;;; 111; ..... .....

So, by only using ';' 因此,仅使用“;” as the delimiter I don't get the wanted results, eg in some db fields I am getting data like ;;1111; 作为分隔符,我没有得到想要的结果,例如,在某些数据库字段中,我正在获取;; 1111;等数据 - normally there should be only numbers. -通常只有数字。

Is there any way to make all the semicolons act as a delimiter? 有什么办法可以使所有分号充当定界符?

Your input txt file is not in proper format. 您输入的txt文件格式不正确。

You can find and replace ;; 您可以找到并替换;; with ; 与; in text editor and then try loading data again into table. 在文本编辑器中,然后尝试再次将数据加载到表中。

Repeat this find and replace process two times to convert all semicolons to one. 重复此查找和替换过程两次,以将所有分号都转换为一个。

\\N between the delimiters in the data file. 数据文件中定界符之间的\\ N。 This marks the field as null when sql loads it. sql加载该字段时,会将其标记为null。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM