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 661<br />

10,Sales,Virginia,1/5/2000<br />

20,Accounting,Virginia,21/6/1999<br />

30,Consulting,Virginia,5/1/2000<br />

40,Finance,Virginia,15/3/2001<br />

you would find this error in your log file, for each input record:<br />

Record 1: Rejected - Error on table DEPT, column ENTIRE_LINE.<br />

Column not found before end of logical record (use TRAILING NULLCOLS)<br />

Here, SQLLDR is telling you that it ran out of data in the record before it ran out of<br />

columns. The solution is easy in this case, <strong>and</strong>, in fact, SQLLDR even tells us what to do: use<br />

TRAILING NULLCOLS. This will have SQLLDR bind a NULL value in for that column if no data<br />

exists in the input record. In this case, adding TRAILING NULLCOLS will cause the bind variable<br />

:ENTIRE_LINE to be NULL. So, you retry with this control file:<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 />

LAST_UPDATED date 'dd/mm/yyyy',<br />

ENTIRE_LINE ":deptno||:dname||:loc||:last_updated"<br />

)<br />

BEGINDATA<br />

10,Sales,Virginia,1/5/2000<br />

20,Accounting,Virginia,21/6/1999<br />

30,Consulting,Virginia,5/1/2000<br />

40,Finance,Virginia,15/3/2001<br />

Now the data in the table is as follows:<br />

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

DEPTNO DNAME LOC ENTIRE_LINE LAST_UPDA<br />

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

10 SALES VIRGINIA 10SalesVirginia1/5/2000 01-MAY-00<br />

20 ACCOUNTING VIRGINIA 20AccountingVirginia21/6/1999 21-JUN-99<br />

30 CONSULTING VIRGINIA 30ConsultingVirginia5/1/2000 05-JAN-00<br />

40 FINANCE VIRGINIA 40FinanceVirginia15/3/2001 15-MAR-01<br />

What makes this feat possible is the way SQLLDR builds its INSERT statement. SQLLDR<br />

will look at the preceding <strong>and</strong> see the DEPTNO, DNAME, LOC, LAST_UPDATED, <strong>and</strong> ENTIRE_LINE<br />

columns in the control file. It will set up five bind variables named after these columns.<br />

Normally, in the absence of any functions, the INSERT statement it builds is simply

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

Saved successfully!

Ooh no, something went wrong!