Databases :: MySql :: Need Help Formatting Fields |
|||
| By: Squibi |
Date: 30/01/2003 00:00:00 |
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 | 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 |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








