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.

700<br />

CHAPTER 15 ■ DATA LOADING AND UNLOADING<br />

The control file that was generated by this shows the following (note that the numbers<br />

in parentheses in bold on the right are not actually in the file; they are solely for reference<br />

purposes):<br />

load data (1)<br />

infile 'emp.dat' "str x'7E0A'" (2)<br />

into table emp (3)<br />

replace (4)<br />

fields terminated by X'2c' enclosed by X'22' (5)<br />

( (6)<br />

EMPNO char(44 ), (7)<br />

ENAME char(20 ), (8)<br />

JOB char(18 ), (9)<br />

MGR char(44 ), (10)<br />

HIREDATE date 'ddmmyyyyhh24miss' , (11)<br />

SAL char(44 ), (12)<br />

COMM char(44 ), (13)<br />

DEPTNO char(44 ), (14)<br />

) (15)<br />

The things to note about this control file are as follows:<br />

• Line (2): We use the STR feature of SQLLDR. We can specify what character or string is<br />

used to terminate a record. This allows us to load data with embedded newlines easily.<br />

The string x'7E0A' is simply a tilde followed by a newline.<br />

• Line (5): We use our separator character <strong>and</strong> enclosure character. We do not use<br />

OPTIONALLY ENCLOSED BY, since we will be enclosing every single field after doubling<br />

any occurrence of the enclosure character in the raw data.<br />

• Line (11): We use a large “numeric” date format. This does two things: it avoids any NLS<br />

issues with regard to the data, <strong>and</strong> it preserves the time component of the date field.<br />

The raw data (.dat) file generated from the preceding code looks like this:<br />

"7369","SMITH","CLERK","7902","17121980000000","800","","20"~<br />

"7499","ALLEN","SALESMAN","7698","20021981000000","1600","300","30"~<br />

"7521","WARD","SALESMAN","7698","22021981000000","1250","500","30"~<br />

"7566","JONES","MANAGER","7839","02041981000000","2975","","20"~<br />

"7654","MARTIN","SALESMAN","7698","28091981000000","1250","1400","30"~<br />

"7698","BLAKE","MANAGER","7839","01051981000000","2850","","30"~<br />

"7782","CLARK","MANAGER","7839","09061981000000","2450","","10"~<br />

"7788","SCOTT","ANALYST","7566","19041987000000","3000","","20"~<br />

"7839","KING","PRESIDENT","","17111981000000","5000","","10"~<br />

"7844","TURNER","SALESMAN","7698","08091981000000","1500","0","30"~<br />

"7876","ADAMS","CLERK","7788","23051987000000","1100","","20"~<br />

"7900","JAMES","CLERK","7698","03121981000000","950","","30"~<br />

"7902","FORD","ANALYST","7566","03121981000000","3000","","20"~<br />

"7934","MILLER","CLERK","7782","23011982000000","1300","","10"~

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

Saved successfully!

Ooh no, something went wrong!