Oct 28, 2002 #1 EvansEd Programmer Joined Sep 30, 2002 Messages 9 Location US I'd like to know how to skip empty rows from a data file when writing my sql loader .ctl file? There will be empty rows in the data file, but I just don't know where they will be.
I'd like to know how to skip empty rows from a data file when writing my sql loader .ctl file? There will be empty rows in the data file, but I just don't know where they will be.
Oct 28, 2002 1 #2 Turkbear Technical User Joined Mar 22, 2002 Messages 8,631 Location US You can add a test to your ctl file that checks the first character in a line and can act on the result: For Instance Code: LOAD DATA INFILE "PUBLIC.DAT" INSERT INTO TABLE mydata when record_type <> ' ' ( RECORD_TYPE POSITION(1:2), PERSON_NUM POSITION(3:8), LAST_NAME POSITION(9:38), FIRST_NAME POSITION(39:68) , MIDDLE_NAME POSITION(69:98) ) should only load lines where there is a non-space in position 1 Upvote 0 Downvote
You can add a test to your ctl file that checks the first character in a line and can act on the result: For Instance Code: LOAD DATA INFILE "PUBLIC.DAT" INSERT INTO TABLE mydata when record_type <> ' ' ( RECORD_TYPE POSITION(1:2), PERSON_NUM POSITION(3:8), LAST_NAME POSITION(9:38), FIRST_NAME POSITION(39:68) , MIDDLE_NAME POSITION(69:98) ) should only load lines where there is a non-space in position 1
Oct 29, 2002 Thread starter #3 EvansEd Programmer Joined Sep 30, 2002 Messages 9 Location US I have a spreadsheet(.csv) file, therefore I can't use POSITION. Any other suggestions? Upvote 0 Downvote
Oct 29, 2002 #4 rcurva Programmer Joined Jul 17, 2001 Messages 548 Location AU Since your file is a comma-delimited one, make use of this; LOAD DATA INFILE "PUBLIC.CSV" INSERT INTO TABLE mydata WHEN record_type <> ' ' FIELDS TERMINATED BY ',' ( RECORD_TYPE INTEGER EXTERNAL, PERSON_NUM INTEGER EXTERNAL, LAST_NAME CHAR, FIRST_NAME CHAR, MIDDLE_NAME CHAR NULLIF (MIDDLE_NAME=BLANKS) ) Robbie "The rule is, not to besiege walled cities if it can possibly be avoided" -- Art of War Upvote 0 Downvote
Since your file is a comma-delimited one, make use of this; LOAD DATA INFILE "PUBLIC.CSV" INSERT INTO TABLE mydata WHEN record_type <> ' ' FIELDS TERMINATED BY ',' ( RECORD_TYPE INTEGER EXTERNAL, PERSON_NUM INTEGER EXTERNAL, LAST_NAME CHAR, FIRST_NAME CHAR, MIDDLE_NAME CHAR NULLIF (MIDDLE_NAME=BLANKS) ) Robbie "The rule is, not to besiege walled cities if it can possibly be avoided" -- Art of War