0

I have a table named 'table1' with the columns:

CSMembers,BCID,Total,Email.

The excel sheet contains the data for this table in this format:

     CSMembers       BCID                 Total           Email
        abc    2,5,7,9,12,17,22,32       10,000      [email protected]
        xyz    1,3,5,7,9,12,17,20,22,33  12,500      [email protected]
        pqr    2,5,7,9,12,17,22,32       11,000      [email protected]
        ttt    2,5,7,9,12,17,22          9,800       [email protected]

the .csv file of this is :

CSMembers,BCID,Total,Email
abc,"2,5,7,9,12,17,22,32","10,000",[email protected]
xyz,"1,3,5,7,9,12,17,20,22,33","12,500",[email protected]
pqr,"2,5,7,9,12,17,22,32","11,000",[email protected]
ttt,"2,5,7,9,12,17,22","9,800",[email protected]

I have used the following code:

 load data local infile 'H:/abc.csv' into table table1
 fields terminated by ',' 
 optionally enclosed by '"'
 lines terminated by '\n' ignore 1 lines
 (CSMembers,BCID,Total,Email);

I am getting the following output:

CSMember    BCID    Total       Email
abc          2       10      [email protected]

xyz          1       12      [email protected]

pqr          2       11      [email protected]

ttt          2       9       [email protected]

But i need this output:

CSMembers   BCID                    Total         Email
    abc  2,5,7,9,12,17,22,32       10,000      [email protected]
    xyz  1,3,5,7,9,12,17,20,22,33  12,500      [email protected]
    pqr  2,5,7,9,12,17,22,32       11,000      [email protected]
    ttt  2,5,7,9,12,17,22          9,800       [email protected]

Can anyone please tell me what is wrong? if I should change the code or the csv file content or both? plese help.

0

1 Answer 1

1

Your schema for the table is possibly wrong bcid and total is probably defined as an int of some kind instead of a string. Numeric fields won't know whether a comma is a separator to another field or simply dividing the number up so it is easily readable. Also input to numeric fields typically accepts the value up to the first non-numeric character i.e. the comma

Sign up to request clarification or add additional context in comments.

2 Comments

For the total field, it should be possible to export a CSV file that does not put commas in numbers.
Another alternative for fixing Total column is to remove commas while loading data by using SET clause of LOAD DATA INFILE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.