加载数据到文件问题
我目前在查询中使用 LOAD DATA INFILE,但我不确定如何分离数据
数据采用以下格式 名字:姓氏
$this->db->query("LOAD DATA INFILE 'names.txt'
INTO names firstname lastname
FIELDS TERMINATED BY ':'");
我将如何使用它从文本文件中获取数据并分割名字:姓氏将名字插入名字 &姓氏变成姓氏?
I'm currently using LOAD DATA INFILE in my query, but I am not sure how to separate the data
The data is in the following format firstname:lastname
$this->db->query("LOAD DATA INFILE 'names.txt'
INTO names firstname lastname
FIELDS TERMINATED BY ':'");
How would I use this to take the data from the text file and split firstname:lastname to insert firstname into firstname & lastname into lastname?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您的表名称是
names
。在这种情况下,查询应该是:那么当然你必须执行该语句。
还要注意换行符、字段包围符和字段转义符,您可以为其指定
[LINES] TERMINATED BY
、[FIELDS] ENCLOSED BY
和[FIELDS ] ESCAPED BY
分别(方括号表示您仅指定LINES
或FIELDS
一次)。I'm assuming your table name is
names
. In which case the query should be:Then of course you have to execute the statement.
Also take care of newline characters, field enclosure characters and field escape characters, for which you specify
[LINES] TERMINATED BY
,[FIELDS] ENCLOSED BY
and[FIELDS] ESCAPED BY
respectively (square brackets meaning that you only specifyLINES
orFIELDS
once).