05.11.2015 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

664<br />

CHAPTER 15 ■ DATA LOADING AND UNLOADING<br />

ops$tkyte@ORA10G> alter table dept add comments varchar2(4000);<br />

Table altered.<br />

We’ll use this column to load text into. An example control file with inline data could be as<br />

follows:<br />

LOAD DATA<br />

INFILE *<br />

INTO TABLE DEPT<br />

REPLACE<br />

FIELDS TERMINATED BY ','<br />

TRAILING NULLCOLS<br />

(DEPTNO,<br />

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

LOC<br />

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

COMMENTS "replace(:comments,'\\n',chr(10))"<br />

)<br />

BEGINDATA<br />

10,Sales,Virginia,This is the Sales\nOffice in Virginia<br />

20,Accounting,Virginia,This is the Accounting\nOffice in Virginia<br />

30,Consulting,Virginia,This is the Consulting\nOffice in Virginia<br />

40,Finance,Virginia,This is the Finance\nOffice in Virginia<br />

Notice how in the call to replace we had to use \\n, not just \n. This is because \n is recognized<br />

by SQLLDR as a newline, <strong>and</strong> SQLLDR would have converted it into a newline, not a<br />

two-character string. When we execute SQLLDR with the preceding control file, the table DEPT<br />

is loaded with the following:<br />

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

DEPTNO DNAME<br />

COMMENTS<br />

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

10 SALES This is the Sales<br />

Office in Virginia<br />

20 ACCOUNTING This is the Accounting<br />

Office in Virginia<br />

30 CONSULTING This is the Consulting<br />

Office in Virginia<br />

40 FINANCE This is the Finance<br />

Office in Virginia<br />

Use the FIX Attribute<br />

The FIX attribute is another method available to us. If we use this, the input data must appear<br />

in fixed-length records. Each record will be exactly the same number of bytes as any other<br />

record in the input data set. When using positional data, use of the FIX attribute is especially

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

Saved successfully!

Ooh no, something went wrong!