Oracle 外部表中的预处理器

PreProcessor in Oracle External Tables

每当我将预处理器子句添加到外部 tables 语句时,我似乎遇到了问题。没有预处理器行,一切正常,但是一旦我添加它,我就会收到各种错误,具体取决于我将它放在访问参数块中的位置,它们是否必须按特定顺序排列?我在网上找不到任何类似的问题。

编辑:另请注意,我知道您可以使用预处理器将压缩文件提供给外部 table。如果我想读取一个压缩文件并附加文件名,是不是就像将它全部放在一个 shell 文件中一样简单?

CREATE TABLE (
    column1 VARCHAR2(40),
    column2 VARCHAR2(40)
)
ORGANIZATION EXTERNAL
(
  TYPE ORACLE_LOADER
  DEFAULT DIRECTORY DMPDIR
    ACCESS PARAMETERS(
        RECORDS DELIMITED BY NEWLINE
        LOGFILE DMPDIR:'test.log'
        BADFILE DMPDIR:'test.bad'
        fields terminated by '^'
        MISSING FIELD VALUES ARE NULL
        REJECT ROWS WITH ALL NULL FIELDS
        preprocessor DMPDIR: 'append_filename.sh'
    )
 LOCATION (DMPDIR: 'testfile.dat')
);

append_filename.sh

#!/bin/bash
sed -e 's!$!,'"${1##*/}"'!' 

这是一个使用 PREPROCESSOR 创建 external table 的小示例。我在 12c:

SQL> select banner from v$version where rownum = 1;

BANNER
----------------------------------------------------------------------------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production

SQL> DROP TABLE validation_header;

Table dropped.

SQL>
SQL> CREATE TABLE validation_header (
  2  header1 VARCHAR2(5),
  3  header2 number,
  4  header3 VARCHAR2(8),
  5  header4 number
  6  )
  7  ORGANIZATION EXTERNAL (
  8  TYPE oracle_loader
  9  DEFAULT DIRECTORY data_pump_dir
 10  ACCESS PARAMETERS (
 11  RECORDS DELIMITED BY NEWLINE
 12  PREPROCESSOR import_ppm:'script.ksh'
 13  LOGFILE import_ppm:'script.log'
 14  FIELDS TERMINATED BY ','
 15  (header1,header2,header3, header4
 16  ))
 17  LOCATION ('script_file.txt')
 18  );

Table created.

SQL>

根据文档,

KUP-04094: preprocessing cannot be performed if Database Vault is installed

  • Cause: The Database Vault option did not permit the execution a program from an Oracle directory object.

  • Action: If preprocessing must be performed, then the Database Vault option must not be installed.