External tables are an important intermediary between external environments and the database. In ORACLE, one cannot imagine data pumps or work with ETL and DWH without them. In general, it is a read-only table that is defined in the database but exists outside the database, meaning that the metadata is stored in the database and the data it contains is outside the database. A table that is connected to an external table looks like a normal table, but it does not have all its functionalities. It can be queried with the SELECT command, but no DML (update, insert, delete) can be done. Advantages:
!Additional Constraints: No CONSTRAINTS can be created and External Table Column cannot be set to SET UNUSED!
To create an external table, we will need to identify the location in the operating system (in the Oracle client's $ORACLE_HOME-database folder) where the external file containing the table will be located.
CREATE OR REPLACE DIRECTORY
directory_name
AS
directory_reference;
Once the directory is created, the owner must grant READ or WRITE access to the USER
The Oracle database provides a number of tools that are part of various packages. The tools that are important for external tables are:
The basic difference between loader and Datapump is that Loader only loads data and Datapump also exports with a specific DMP extension.
The create statement looks like this:
CREATE TABLE INVOICES_EXTERNAL
( INV_ID CHAR(3),
INVOICE_DATE CHAR(11),
PRODUCT_ID CHAR(5)
) ORGANIZATION EXTERNAL
(TYPE oracle_loader
DEFAULT DIRECTORY t_orcl_ext
ACCESS PARAMETERS
(
RECORDS DELIMITED BY newline
SKIP 2 FIELDS(
INV_ID CHAR(3),
INVOICE_DATE CHAR(11),
PRODUCT_ID CHAR(5)
)
)
LOCATION ('inv.txt')
);
/* description r.2-4 column declaration
yr.1-5 classic create script + keyword "ORGANIZATION EXTERNAL"
From line 6, the definition regarding the external file
r.6 Access driver type for data import (oracle_loader) (MUST!)
r.7 referenced directory
r. 8-16 input parameters
r.10 as the rows are separated
r.11 which lines are skipped
r.11-15 column declaration (must have the same name and variable type as line 2-4
r.17 referenced file (MUST!)*/
Using examples, we showed how external tables work in Oracle. We found out what their use is and what role they play in the ETL process and DWH. More examples can be found here