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.

CHAPTER 15 ■ DATA LOADING AND UNLOADING 655<br />

Another popular format is tab-delimited data, which is data separated by tabs rather than<br />

commas. There are two ways to load this data using the TERMINATED BY clause:<br />

• TERMINATED BY X'09' (the tab character using hexadecimal format; in ASCII, 9 is a tab<br />

character)<br />

• TERMINATED BY WHITESPACE<br />

The two are very different in implementation, as the following shows. Using the DEPT table<br />

from earlier, we’ll load using this control file:<br />

LOAD DATA<br />

INFILE *<br />

INTO TABLE DEPT<br />

REPLACE<br />

FIELDS TERMINATED BY WHITESPACE<br />

(DEPTNO, DNAME, LOC)<br />

BEGINDATA<br />

10 Sales Virginia<br />

It is not readily visible on the page, but there are two tabs between each piece of data<br />

here. The data line is really<br />

10\t\tSales\t\tVirginia<br />

where the \t is the universally recognized tab escape sequence. When you use this control file<br />

with the TERMINATED BY WHITESPACE clause as shown previously, the resulting data in the table<br />

DEPT is<br />

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

DEPTNO DNAME<br />

LOC<br />

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

10 Sales Virginia<br />

TERMINATED BY WHITESPACE parses the string by looking for the first occurrence of whitespace<br />

(tab, blank, or newline), <strong>and</strong> then it continues until it finds the next non-whitespace<br />

character. Hence, when it parsed the data, DEPTNO had 10 assigned to it, the two subsequent<br />

tabs were considered as whitespace, Sales was assigned to DNAME, <strong>and</strong> so on.<br />

On the other h<strong>and</strong>, if you were to use FIELDS TERMINATED BY X'09', as the following modified<br />

control file does:<br />

...<br />

FIELDS TERMINATED BY X'09'<br />

(DEPTNO, DNAME, LOC )<br />

...

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

Saved successfully!

Ooh no, something went wrong!