visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Databases :: MySql :: load data in file query


By: phpsnook India  Date: 23/10/2008 09:30:04  English  Points: 20 Status: Answered
Quality : Excellent
hai

i am using LOAD DATA INFILE command to load a csv to the database,in a particular column i want the white spaces to be replaced ......can i use REPLACE for tht
pls help
By: VGR Date: 23/10/2008 18:34:05 English  Type : Comment
I usually LOAD DATA INFI with stupid varchar(x) columns (appropriate number of columns), and the I convert the import table to a real table doing replace(), case when..., format changes (string to numeric, saves space) etc

Indeed you can't do both operations (importing and data changes) in one go using LOAD DATA INFILE.

HTH
By: ushastry Date: 29/10/2008 11:42:57 English  Type : Answer
Try this...

load data local infile 'filename.csv' into table tableName
fields terminated by ','
optionally enclosed by '"'
lines terminated by '\r\n'
(
@col1
,@col2
,@col3
)
set
col1 = REPLACE(@col1,' ','')
col2 = REPLACE(@col2,' ','')
col3 = REPLACE(@col3,' ','')
;


Syntax can be found here

http://dev.mysql.com/doc/refman/5.0/en/load-data.html
By: VGR Date: 29/10/2008 17:54:36 English  Type : Comment
thanks ushastry, it's true . It's available "as of MySQL 5.0.3". I suppose I've to upgrade my brain ;-)
By: ushastry Date: 29/10/2008 18:05:03 English  Type : Comment
Welcome VGR.
BTW are you the VGR from experts-exchange(EE)? I'm quite familiar with this name 'VGR' & valuable solutions on the EE forums.

Thanks,
Umesh Shastry
By: VGR Date: 29/10/2008 18:57:53 English  Type : Comment
yes I am, but I was active on EE.com only from Oct 2002 to Oct 2003 ;-)
Since Oct 2003, we opened this (really free) site.
By: OpConsole Date: 03/04/2011 19:02:30 English  Type : Comment
force close

Do register to be able to answer

EContact
browser fav
page generated in 303.871870 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page