Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2012
    Posts
    3

    Unanswered: Can I import a .txt file by string start/end position

    I'm trying to import a large .txt file into SQL but a regular bulk insert will not do as there are no delimiters. Each line contains roughly 1080 bytes of data that are scrunched together. (1 byte - represents one character) The only thing I know for sure is the start and end position for each column entry which is fixed-format. For example:

    col1 (1,3)
    col2 (4,6)
    col3 (7,7)
    col4 (8,30)
    col5 (31,39)
    ...
    colN (1050, 1080)

    This occurs for X,XXX,XXX rows. So for each row, I want to pull in the column info based on the string position of the data.

    How can I do this in SQL? All I have found so far is bulk insert entry...

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I'd reprocess the file using whatever tools you have to hand
    whether thats Excel or similar or somethign else
    if it was in a spreadsheet I'd save the resultant output as a CSV
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Have a look at this post. It is possible by using "FIELDS TERMINATED BY ''" in your LOAD DATA INFILE command.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by it-iss.com View Post
    Have a look at this post. It is possible by using "FIELDS TERMINATED BY ''" in your LOAD DATA INFILE command.
    which is fine and dandy if the incoming stream is delimited by something. however my impression from the OP is that there are no delimiters, just a stream of contiguous data per line
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    By adding in the FIELDS TERMINATED BY '' means that it will take the sizing based on the table definition of the columns (which must be all varchar or char) and means that no delimiter is provided. In the example that I have given it shows how it works.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •