visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
316 experts, 1194 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 :: Need Help Formatting Fields


By: Squibi U.S.A.  Date: 30/01/2003 00:00:00  English  Points: 50 Status: Answered
Quality : Excellent
I was wondering the syntax or if there are any tips on formatting fields in my test DB. For example I loaded a CSV file into the DB using ...terminated by '\'; statement. now all the fields are in the right columns but the data is enclosed in "" ie."test". I know you can use ltrim and rtrim or left and right but I can only seem to get them to work in select statements. Any insight would help. I should remeber how to do this but I am at a blank right know.

Thanks in advance!
By: VGR Date: 30/01/2003 09:17:00 English  Type : Answer
easy. Very easy.


RTFM ;-)

Look at the documentation for the import of data : <A HREF="http://www.mysql.com/doc/en/LOAD_DATA.html">http://www.mysql.com/doc/en/LOAD_DATA.html</a> (LOAD DATA INFILE).

use DELIMITED, ENCLOSED, with TERMINATED BY and you'll be saved 8-)

LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.txt'
[REPLACE | IGNORE]
INTO TABLE tbl_name
[FIELDS
[TERMINATED BY '\t']
[[OPTIONALLY] ENCLOSED BY '']
[ESCAPED BY '\\' ]
]
[LINES TERMINATED BY '\n']
[IGNORE number LINES]
[(col_name,...)]



defaults :
If you don't specify a FIELDS clause, the defaults are the same as if you had written this:

FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\'

If you don't specify a LINES clause, the default is the same as if you had written this:

LINES TERMINATED BY '\n'

it should be easy to find the right filter for your raw CSV data.

Regards



Do register to be able to answer

EContact
browser fav
page generated in 290.979860 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page