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 3 ■ FILES 113<br />

tkyte@ORA10G> select *<br />

2 from nls_database_parameters<br />

3 where parameter = 'NLS_CHARACTERSET';<br />

PARAMETER<br />

VALUE<br />

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

NLS_CHARACTERSET<br />

WE8MSWIN1252<br />

<strong>Oracle</strong> has the ability now to recognize the differing character sets due to the Data Pump<br />

file format <strong>and</strong> deal with them. Character-set conversion can be performed on the fly as<br />

needed to make the data “correct” in each database’s representation.<br />

Again, we’ll come back to the Data Pump file format in Chapter 15, but this section should<br />

give you an overall feel for what it is about <strong>and</strong> what might be contained in the file.<br />

Flat Files<br />

Flat files have been around since the dawn of electronic data processing. We see them literally<br />

every day. The alert log described previously is a flat file.<br />

I found these definitions for “flat file” on the Web <strong>and</strong> feel they pretty much wrap it up:<br />

An electronic record that is stripped of all specific application (program) formats. This<br />

allows the data elements to be migrated into other applications for manipulation.<br />

This mode of stripping electronic data prevents data loss due to hardware <strong>and</strong> proprietary<br />

software obsolescence. 1<br />

A computer file where all the information is run together in a signal character string. 2<br />

A flat file is simply a file whereby each “line” is a “record,” <strong>and</strong> each line has some text<br />

delimited, typically by a comma or pipe (vertical bar). Flat files are easily read by <strong>Oracle</strong> using<br />

either the legacy data-loading tool SQLLDR or external tables—in fact, I will cover this in<br />

detail in Chapter 15 (external tables are also covered in Chapter 10). Flat files, however, are not<br />

something produced so easily by <strong>Oracle</strong>—for whatever reason, there is no simple comm<strong>and</strong>line<br />

tool to export information in a flat file. Tools such as HTMLDB <strong>and</strong> Enterprise Manager<br />

facilitate this process, but there are no official comm<strong>and</strong>-line tools that are easily usable in<br />

scripts <strong>and</strong> such to perform this operation.<br />

That is one reason I decided to mention flat files in this chapter: to propose a set of tools<br />

that is capable of producing simple flat files. Over the years, I have developed three methods<br />

to accomplish this task, each appropriate in its own right. The first uses PL/SQL <strong>and</strong> UTL_FILE<br />

with dynamic SQL to accomplish the job. With small volumes of data (hundreds or thous<strong>and</strong>s<br />

of rows), this tool is sufficiently flexible <strong>and</strong> fast enough to get the job done. However, it must<br />

1. See http://osulibrary.oregonstate.edu/archives/h<strong>and</strong>book/definitions.<br />

2. See http://www.oregoninnovation.org/pressroom/glossary.d-f.html.

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

Saved successfully!

Ooh no, something went wrong!