5. Populating Tables : Advanced Use of the Copy Statement : Populate Multiple Database Tables Using Multiple FIles : Multi-line File Records
 
Share this page                  
Multi-line File Records
Another feature of the COPY statement is that it can read multi-line records from a file into a single row in a table. For instance, suppose that for viewing convenience, the detail file is formatted so that each record requires three lines. That file looks like this:
1, 5173
10179A, No.2 Rainbow Pencils
0.29
1, 5175
73122Z, 1998 Rainbow Calendars
4.90
Load these values into the pricetemp table with the following COPY statement:
COPY TABLE pricetemp (orderno = CHAR(0)COMMA, invno = CHAR(0)
    NL, catno = CHAR(0)COMMA, descript = d0NL,  price =
    CHAR(0)nl) FROM 'file2';
It does not matter that newlines have been substituted for commas as delimiters within each record. The only requirement is that the data fields be uniform in number and order, the same as for single-line records.