Using External Tables
By Ahmed Baraka
Oracle Database Administration from Zero to Hero- - a course by Ahmed Baraka
Objectives
By the end of this lecture, you will learn how to perform the following:
• Describe External Tables
• Use External Tables with ORACLE_LOADER driver
• Use External Tables with ORACLE_DATAPUMP driver
Oracle Database Administration from Zero to Hero- - a course by Ahmed Baraka
External Tables
Database
PGA
Server ORACLE_LOADER
process driver
Text Files
SELECT ...
FROM EXT_TABLE ext_table
WHERE ...
(Metadata Only)
ORACLE_DATAPUMP
driver
Binary Files
Oracle Database Administration from Zero to Hero- - a course by Ahmed Baraka
About External Tables
• Used to access data in external files as if it were in a table in the database
• No DML operations are possible, and no index can be created on them
• Accessing files stored on DNFS or Storage Object is supported
• Access driver options:
- ORACLE_LOADER: used to access text files. Cannot be used to load text files.
- ORACLE_DATAPUMP: used to access Data Pump based files (dump files). Allows
unloading and loading external data.
- ORACLE_HDFS: access data stored in HDFS in Apache Hadoop
- ORACLE_HIVE: access data stored in Hive Tables in Apache Hadoop
- ORACLE_BIGDATA: enables read-only access to data stored in both structured and
unstructured formats, including Apache Parquet, Apache Avro, Apache ORC, and
text formats
Oracle Database Administration from Zero to Hero- - a course by Ahmed Baraka
About External Tables
• With ORACLE_LOADER:
- We can perform data loading from external flat files
- Used to read data saved in flat files
• With ORACLE_DATAPUMP:
- We can perform unloading data into external binary files using external table and
loading back into a database also using external tables
- Better for exchanging data between Oracle databases
Oracle Database Administration from Zero to Hero- - a course by Ahmed Baraka
External Tables with ORACLE_LOADER Example
CREATE TABLE ext_emp
(EMPLOYEE_ID NUMBER(4),
FIRST_NAME VARCHAR2(20),
LAST_NAME VARCHAR2(25),
HIRE_DATE DATE)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER DEFAULT DIRECTORY extab_dat_dir
ACCESS PARAMETERS
( RECORDS DELIMITED BY NEWLINE
BADFILE EXTAB_BAD_DIR:'empxt.bad'
LOGFILE EXTAB_LOG_DIR:'empxt.log'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
MISSING FIELD VALUES ARE NULL
( employee_id, first_name, last_name,
hire_date char date_format date mask "dd-Mon-yyyy"))
LOCATION ('empxt1.dat') )
REJECT LIMIT UNLIMITED;
Oracle Database Administration from Zero to Hero- - a course by Ahmed Baraka
External Tables with ORACLE_LOADER with Parallelism
Example
CREATE TABLE ext_emp
(employee_id NUMBER(4),
first_name VARCHAR2(20),
last_name VARCHAR2(25),
hire_date DATE)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER DEFAULT DIRECTORY extab_dat_dir
ACCESS PARAMETERS
( RECORDS DELIMITED BY NEWLINE
BADFILE EXTAB_BAD_DIR:'empxt%a_%p.bad'
LOGFILE EXTAB_LOG_DIR:'empxt%a_%p.log'
FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
( employee_id, first_name, last_name,
hire_date char date_format date mask "dd-Mon-yyyy"))
LOCATION ('empxt1.dat', 'empxt2.dat') )
PARALLEL REJECT LIMIT UNLIMITED;
Oracle Database Administration from Zero to Hero- - a course by Ahmed Baraka
Unloading External Table Population with
ORACLE_DATAPUMP
CREATE TABLE ext_emp_dump
(FIRST_NAME, LAST_NAME, DEPARTMENT_NAME)
ORGANIZATION EXTERNAL
(
TYPE ORACLE_DATAPUMP
DEFAULT DIRECTORY ext_dir
LOCATION ('emp.exp')
)
AS
SELECT e.first_name,e.last_name,d.department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id AND
d.department_name in ('Marketing', 'Operations');
Oracle Database Administration from Zero to Hero- - a course by Ahmed Baraka
Loading External Table Population with
ORACLE_DATAPUMP
CREATE TABLE ext_emp_dump
(FIRST_NAME VARCHAR2(10), LAST_NAME VARCHAR2(10), DEPARTMENT_NAME
VARCHAR2(10))
ORGANIZATION EXTERNAL
(
TYPE ORACLE_DATAPUMP
DEFAULT DIRECTORY ext_dir
LOCATION ('emp.exp')
)
/
Oracle Database Administration from Zero to Hero- - a course by Ahmed Baraka
Enabling Parallelism
CREATE TABLE orders_xt
ORGANIZATION EXTERNAL
( TYPE ORACLE_DATAPUMP
DEFAULT DIRECTORY ext_dir
LOCATION ( 'ord1.dmp', 'ord2.dmp', 'ord3.dmp', 'ord4.dmp')
)
PARALLEL 4
AS
SELECT *
FROM orders;
Oracle Database Administration from Zero to Hero- - a course by Ahmed Baraka
Obtaining Information about External Tables
Column Description
*_EXTERNAL_TABLES Specific attributes of external tables in the database
*_EXTERNAL_LOCATIONS Data sources for external tables
*_DIRECTORIES Describes the directory objects in the database
Oracle Database Administration from Zero to Hero- - a course by Ahmed Baraka
Summary
By the end of this lecture, you should have learnt how to perform the following:
• Describe External Tables
• Use External Tables with ORACLE_LOADER driver
• Use External Tables with ORACLE_DATAPUMP driver
Oracle Database Administration from Zero to Hero- - a course by Ahmed Baraka