how to specify row delimiter when using bcp with a format file

前端 未结 2 1537
攒了一身酷
攒了一身酷 2020-12-22 00:22

I am using bcp utility to import data into Sybase database on Solaris system

Since the bcp file is generated by another xml pa

2条回答
  •  梦毁少年i
    2020-12-22 01:07

    As most of the loader utilities, BCP does not read rows, it just gets a bunch of bytes from the source file, therefore, you have to specify the end line character on the .fmt file mostly when the end of line character can be different depending on the encoding of the file.

    For example, in the example you provided, you have this on the source file:

    603289|Aug 20 2011 12:00AM|YYY aaa OVD|KLYYP8
    603284|Aug 22 2011 12:00AM|XXX bbb OVD|KLPK06
    

    But depending on the Encoding you will have this:

    603289|Aug 20 2011 12:00AM|YYY aaa OVD|KLYYP8\n603284|Aug 22 2011 12:00AM|XXX bbb OVD|KLPK06
    

    or this:

    603289|Aug 20 2011 12:00AM|YYY aaa OVD|KLYYP8\n\r603284|Aug 22 2011 12:00AM|XXX bbb OVD|KLPK06
    

    That's why the change of the terminator you did on the last column is so important:

    10.0
    4
    1  SYBCHAR   0  12   "|" 3 ver
    2  SYBCHAR   0  26   "|" 2 first_dt
    3  SYBCHAR   0  60   "|" 4 name1
    4  SYBCHAR   0  10   "\n" 1 name2   * The last terminator was not "|"
    

    The following image shows what means each component on the format file (I got it from here):

    • By the way, please notice the last terminator!

提交回复
热议问题