Oracle RDBMS 11gR2 – New PREPROCESSOR Syntax for External Table Use

Marco Gralike

One of the other small but very useful new features in the Oracle 11gR2 database is the addition of a PREPROCESSOR parameter for the create EXTERNAL table statement. This PREPROCESSOR clause gives you the ability to execute an executable or executable (shell) script that handles your data before it gets presented. The PREPOCESSOR clause is part of the ORACLE_LOADER access driver

The Oracle 11gR2 Database Utilities Manual states:

The preprocessor program converts the data to a record format supported by the access driver and then
writes the converted record data to standard output (stdout), which the access driver reads as input.

SQL> CREATE TABLE xtab (recno varchar2(2000))
     2    ORGANIZATION EXTERNAL (
     3    TYPE ORACLE_LOADER
     4    DEFAULT DIRECTORY data_dir
     5    ACCESS PARAMETERS (
     6    RECORDS DELIMITED BY NEWLINE
     7    PREPROCESSOR execdir:'zcat'
     8    FIELDS (recno char(2000)))
     9    LOCATION ('foo.dat.gz'))
    10    REJECT LIMIT UNLIMITED;

SQL> CREATE TABLE xtab (recno varchar2(2000))
     2    ORGANIZATION EXTERNAL (
     3    TYPE ORACLE_LOADER
     4    DEFAULT DIRECTORY data_dir
     5    ACCESS PARAMETERS (
     6    RECORDS DELIMITED BY NEWLINE
     7    PREPROCESSOR execdir:'uncompress.sh'
     8    FIELDS (recno char(2000)))
     9    LOCATION ('foo.dat.gz'))
    10    REJECT LIMIT UNLIMITED;

So as the example demonstrates, you can uncompress a zipped file to your "liking", manipulating the format before use.

Especially the scripting possibilities makes it a very interesting option. There are, of course, some security limitations, for example the referenced script must be executable and the executable script or referenced binary executable must "exist" in the directory defined by your directory alias.

See for more information the Oracle 11gR2 Database Utilities Manual

A small addition, but a very powerfull one…!

😉

Next Post

Oracle SQL and PL/SQL: juggling with user defined types (ADT) and XMLType - for creating an ADT based XML Service API

Facebook0TwitterLinkedinPackages in the Oracle Database are a fine construct to use for creating a service API at PL/SQL level – that through JDBC or other connections into the database can quickly be exposed at other levels than just internally for PL/SQL. A service API has a number of characteristics, that […]