If you are writing text in a fixed-ASCII format, separate lines for each record are helpful. For example, consider a table with the following schema:
TABLE sample ( lastname CHAR(10), firstname CHAR(10), dateofbirth DATE);
This table contains the following values:
Adams Sam 10-02-1957
Smith John 01-01-1920
Next, consider an external table with the following schema:
CREATE EXTERNAL TABLE sample_ext ( lastname CHAR(10) EXTERNAL CHAR(10), firstname CHAR(10) EXTERNAL CHAR(10), dateofbirth DATE EXTERNAL CHAR(12));
Unloading sample_ext without an end-of-line character produces the following output:
Adams Sam 10-02-1957 Smith John 01-01-1920
An end-of-line character makes the date more legible and clear. If you use delimited format defaults, an end-of-line character is automatic. However, for fixed-format unloads, you need to add an end-of-line character to your records. You can add end-of-line characters in several ways.
To add an end-of-line character, you can write the fixed-length records to a data file and then modify the data file with a program or script. For example, you could use a C program to find the length of each record, locate the end of a line, and then add an end-of-line character.
To add an end-of-line character, select a final value from a table that contains a newline character. You can use an external table to load the newline character in your internal table, as in the following example:
echo "" > /tmp/cr.fixed
CREATE TABLE dummyCr (cr CHAR(1));
CREATE EXTERNAL TABLE x_cr (cr (CHAR(1) EXTERNAL CHAR(1))
USING (DATAFILES ("disk:1:/tmp/cr.fixed"), FORMAT 'FIXED');
INSERT INTO dummyCr SELECT * FROM x_cr;
The internal table, dummyCr, now contains an end-of-line character that you can use to unload in a SELECT statement:
CREATE EXTERNAL TABLE sample_ext ( lastname CHAR(10) EXTERNAL CHAR(10), firstname CHAR(10) EXTERNAL CHAR(10), dateofbirth DATE EXTERNAL CHAR(12), eol CHAR(1) EXTERNAL CHAR(1)) USING (DATAFILES ....), FORMAT 'FIXED');
INSERT INTO sample_ext(lastname, firstname, dateofbirth, eol) SELECT a.lastname, a.firstname, a.dateofbirth, b.cr FROM mytable a, dummyCr b;