2

在 mysql db 中成功导入 .csv 文件的内容后,我遇到了一个奇怪的问题。csv 文件中的数据已成功导入 db 表,但如果我在表上运行任何带有 Condition 的 SQL 查询,则不会返回任何查询结果。我能够运行查询:

select * from mst_question

但如果指定条件且满足条件则不返回结果

select * from mst_question where qtype='single'

该表具有列 qtype 包含条件文本“single”但不返回任何结果的行。

奇怪的是,如果我编辑表中的“qtype”列内容并通过键入“single”替换测试“single”,则返回该行......对于我编辑的每一行!

我的 .csv 文件:

que_id,test_id,que_desc,ans1,ans2,ans3,ans4,true_ans,qtype
,11,In which year is the HTML specification supposed to be complete and finalized?,2012,2015,2020,2022,D,single
,11,Which of the following doctypes was introduced by HTML5?,<!doctype xhtml>,<!doctype html>,"<!doctype html PUBLIC ""-//W3C//DTD HTML 5.0 Transitional//EN"">","<!doctype html5 PUBLIC ""-//W3C//DTD HTML 5.0 Transitional//EN"">",B,single
,11,How do you stop crawlers from following links to sites you don't want to be associated with?,"<a href=""#"" rel=""nofollow""> ","<a href=""#"" rel=""dontgo""> ","<a href=""#"" rel=""nogo""> ","<a href=""#"" rel=""noassociation"">",A,single
,11,Which tag is used to define a section of the page that has content that is related but not critical to the main content in HTML5?,<article> ,<sidesection> ,<aside> ,<section> ,C,single
,11,The <article> is used to contain a main article. What is the tag used to break it into sections?,<article> ,<time> ,<aside> ,<section> ,D,single

我的 LOAD DATA LOCAL INFILE 语法:

LOAD DATA LOCAL INFILE 'quest.csv' INTO TABLE mst_question FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY """" IGNORE 1 LINES

执行 LOAD DATA LOCAL INFILE 后的输出:

(5 row(s)affected)
(0 ms taken)

我的 SQL 查询(给出结果):

select * from mst_question

结果

(5 row(s)returned)
(0 ms taken)

我的 SQL 查询条件简单(没有结果):

select * from mst_question where qtype='single'

结果 :

(0 row(s)returned)
(0 ms taken)

我究竟做错了什么 ????

找不到……请指教……

4

1 回答 1

2

我的猜测是您的文件有 Windows 换行符:

...0,2022,D,single\r\n

您没有指定LINES TERMINATED BY '\r\n'子句,因此 MySQL 可能默认为 Unix 样式 ( \n),因此它实际上会导入single\r您的列。

您可以使用 . 检查确切的列内容HEX()

于 2013-02-04T16:21:47.383 回答