Oracle RDBMS 11gR2 - New PREPROCESSOR Syntax for External Table Use 13422386 1019544571447648 7687716130941590224 o1

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

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…!

😉

Tags: