我正在将CSV文件导入Heidi SQL。我使用以下代码创建了表:
create table all_data
(
Keyword varchar(1000),
Position int,
Previous_Position int,
Search_Volume int,
KW_Difficulty float,
URL varchar(1000),
Post_title varchar(1000),
Post_URL varchar(1000),
Genre varchar(1000),
Location varchar(1000),
Avg_Daily_Visitors float,
pageviews int
)
;
但是在Avg_Daily_visitors列中,它有“\ N”,其中没有值。我一直用这段代码导入数据:
load data local infile 'C:/filepath.../All_Data.csv'
replace into table all_data
fields terminated by ','
enclosed by '"'
escaped by '"'
lines terminated by "\r\n"
ignore 1 rows
set
Avg_Daily_Visitors = replace(Avg_Daily_Visitors,"\N",0),
pageviews = replace(pageviews,"\N", 0)
;
但它没有用0替换值,这是我想要实现的。如何让Heidi SQL在导入时用“0”替换“\ N”?
感谢。
答案 0 :(得分:0)
首先将您读取的值分配给变量,然后处理该变量。为此,您可以指定目标表的列,但是要指定一个变量而不是要替换的列。
load data local infile 'C:/filepath.../All_Data.csv'
replace into table all_data
fields terminated by ','
enclosed by '"'
escaped by '"'
lines terminated by "\r\n"
ignore 1 rows
(column_1, column_2, @variable1, @variable2, column_5)
set
Avg_Daily_Visitors = replace(@variable1,"\N",0),
pageviews = replace(@variable2,"\N", 0)
;