05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

674<br />

CHAPTER 15 ■ DATA LOADING AND UNLOADING<br />

Each record ends with a pipe symbol (|), followed by the end-of-line marker. The text for<br />

department 40 is much longer than the rest, with many newlines, embedded quotes, <strong>and</strong><br />

commas. Given this data file, we can create a control file such as this:<br />

LOAD DATA<br />

INFILE demo.dat "str X'7C0A'"<br />

INTO TABLE DEPT<br />

REPLACE<br />

FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'<br />

TRAILING NULLCOLS<br />

(DEPTNO,<br />

DNAME "upper(:dname)",<br />

LOC<br />

"upper(:loc)",<br />

COMMENTS char(1000000)<br />

)<br />

■Note This example is from UNIX, where the end-of-line marker is 1 byte, hence the STR setting in the<br />

preceding control file. On Windows, it would have to be '7C0D0A'.<br />

To load the data file, we specify CHAR(1000000) on the column COMMENTS since SQLLDR<br />

defaults to CHAR(255) for any input field. The CHAR(1000000) will allow SQLLDR to h<strong>and</strong>le up<br />

to 1,000,000 bytes of input text. You must set this to a value that is larger than any expected<br />

chunk of text in the input file. Reviewing the loaded data, we see the following:<br />

ops$tkyte@ORA10G> select comments from dept;<br />

COMMENTS<br />

-------------------------------------------------------------------------------<br />

This is the Consulting<br />

Office in Virginia<br />

This is the Finance<br />

Office in Virginia, it has embedded commas <strong>and</strong> is<br />

much longer than the other comments field. If you<br />

feel the need to add double quoted text in here like<br />

this: "You will need to double up those quotes!" to<br />

preserve them in the string. This field keeps going for up to<br />

1000000 bytes or until we hit the magic end of record marker,<br />

the | followed by an end of line - it is right here -><br />

This is the Sales<br />

Office in Virginia<br />

This is the Accounting<br />

Office in Virginia

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!