I have a csv file where one of the fields contains the new line character, when I load the file using the sql loader it gives me the error.
Here is the data file
4/24/2000,Chemical Engineering Graduate Student Association (ChEGSA) at Carnegie Mellon University,"Carnegie Mellon University
Department of Chemical Engineering
Attn: Warren R. Hoffmaster
1107 Doherty Hall
Pittsburgh, Pennsylvania 15213-3890",412-268-2230,,22nd Annual Chemical Engineering Symposium,"Oct 12 & 13, 2000",Carnegie Mellon University,,500.00,500,C Cimarusti,M Futran,,,500,,"Check dated: 09/01/00
Letter dated: 09/12/00",,,1517273,
and the control file
LOAD DATA
infile 'f:\projects\contributions\migration\contributionstable1.csv'
badfile 'f:\projects\contributions\migration\contributionstable.bad'
discardfile 'f:\projects\contributions\migration\contributionstable.dis'
TRUNCATE
INTO TABLE temp_cont_table
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
(req_received_dt,
requestor_name,
req_address CHAR "replace(:req_address, chr(10), '')",
req_phone,
req_taxid,
req_eventname,
req_eventdates,
req_location,
req_min_amtreq,
req_amtreq,
req_amtfunded,
req_reviewers,
req_reviewers2,
req_reviewers3,
req_reviewers4,
req_recommend,
req_sentrev CHAR "replace(:req_address, chr(10), '')",
req_history CHAR "replace(:req_address, chr(10), '')",
req_checkreq,
req_paydate,
req_checknbr,
req_chk_date,
req_cont_table_id "cont_table_seq.nextval")
loader is treating each new line character is new record .
Can anybody help.
by: kursattuncelPosted on 2002-12-13 at 00:59:17ID: 7577061
1.) Copy your csv file as "input.csv"
2.) Save the attached file as "furnish.c" and compile
under unix
(gcc -o furnish furnish.c)
3.) run the command ./furnish > output.csv
4.) check the output.csv to make sure that everything is correct.
Best Regards,
Kursat Tuncel
--- cut here---
// furnish.c
// written by Kursat Tuncel, kursattuncel@hotmail.com
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
char buffer[1024];
char nextchar;
FILE *input;
int count = 0;
int slot = 0;
input = fopen("input.csv","r");
while(!feof(input))
{
nextchar = getc(input);
if (nextchar == ',') count++;
if (count != 23) buffer[slot++] = nextchar;
else
{
buffer[slot++] = nextchar;
buffer[slot] = '\0';
slot = 0;
while (buffer[slot] != '\0')
{
if (buffer[slot] == '\n' && slot != 0)
buffer[slot] = ' ';
slot++;
}
count = 0;
slot = 0;
printf("%s", buffer);
}
}
}