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.

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

To load fixed-width positional data, you will use the POSITION keyword in the control file,<br />

for example:<br />

LOAD DATA<br />

INFILE *<br />

INTO TABLE DEPT<br />

REPLACE<br />

( DEPTNO position(1:2),<br />

DNAME position(3:16),<br />

LOC position(17:29)<br />

)<br />

BEGINDATA<br />

10Accounting Virginia,USA<br />

This control file does not employ the FIELDS TERMINATED BY clause; rather, it uses POSITION<br />

to tell SQLLDR where fields begin <strong>and</strong> end. Of interest with the POSITION clause is that we<br />

could use overlapping positions, <strong>and</strong> go back <strong>and</strong> forth in the record. For example, if we were<br />

to alter the DEPT table as follows:<br />

ops$tkyte@ORA10G> alter table dept add entire_line varchar(29);<br />

Table altered.<br />

<strong>and</strong> then use the following control file:<br />

LOAD DATA<br />

INFILE *<br />

INTO TABLE DEPT<br />

REPLACE<br />

( DEPTNO position(1:2),<br />

DNAME position(3:16),<br />

LOC position(17:29),<br />

ENTIRE_LINE position(1:29)<br />

)<br />

BEGINDATA<br />

10Accounting Virginia,USA<br />

the field ENTIRE_LINE is defined as POSITION(1:29). It extracts its data from all 29 bytes of input<br />

data, whereas the other fields are substrings of the input data. The outcome of the this control<br />

file will be as follows:<br />

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

DEPTNO DNAME LOC ENTIRE_LINE<br />

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

10 Accounting Virginia,USA 10Accounting Virginia,USA<br />

When using POSITION, we can use relative or absolute offsets. In the preceding example,<br />

we used absolute offsets. We specifically denoted where fields begin <strong>and</strong> where they end. We<br />

could have written the preceding control file as follows:

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

Saved successfully!

Ooh no, something went wrong!